-
-
Save simongeilfus/fbdc4b9f98e02edc685b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SomeData { | |
template<class Archive> | |
void serialize(Archive & archive); | |
std::string mName; | |
float mFloat0, mFloat1; | |
}; | |
template<class Archive> | |
void SomeData::serialize(Archive & archive) | |
{ | |
archive( mName, mFloat0, mFloat1 ); | |
} | |
std::vector<SomeData> mMyData; | |
float mSomeOtherData0; | |
bool mSomeOtherData1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SerialiseApp::fileOpen( bool forceDefault ) | |
{ | |
fs::path path = forceDefault ? getAssetPath( "" ) / "default.json" : getOpenFilePath(); | |
if( !path.empty() && fs::exists( path ) ){ | |
try { | |
std::ifstream is( path.c_str() ); | |
cereal::JSONInputArchive archive( is ); | |
archive( mMyData, mSomeOtherData0, mSomeOtherData1 ); | |
mCurrentFilePath = path; | |
} | |
catch( const std::exception &exc ){ | |
CI_LOG_EXCEPTION( "Open File", exc ); | |
} | |
} | |
} | |
void SerialiseApp::fileSave( bool forceDefault ) | |
{ | |
fs::path path = mCurrentFilePath; | |
if( path.empty() || forceDefault ){ | |
path = getAssetPath( "" ) / "default.json"; | |
} | |
std::ofstream os( path.c_str() ); | |
cereal::JSONOutputArchive archive( os ); | |
archive( mMyData, mSomeOtherData0, mSomeOtherData1 ); | |
} | |
void SerialiseApp::fileSaveAs() | |
{ | |
fs::path path = getSaveFilePath(); | |
if( !path.empty() ){ | |
std::ofstream os( path.c_str() ); | |
cereal::JSONOutputArchive archive( os ); | |
archive( mMyData, mSomeOtherData0, mSomeOtherData1 ); | |
mCurrentFilePath = path; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
ui::ScopedMainMenuBar mainMenu; | |
// File Menu | |
if( ui::BeginMenu( "File" ) ) { | |
if( ui::MenuItem( "New" ) ) | |
fileNew(); | |
if( ui::MenuItem( "Open" ) ) | |
fileOpen(); | |
if( ui::MenuItem( "Save" ) ) | |
fileSave(); | |
if( ui::MenuItem( "Save As" ) ) | |
fileSaveAs(); | |
ui::EndMenu(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment