Skip to content

Instantly share code, notes, and snippets.

@simongeilfus
Last active June 26, 2017 22:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongeilfus/fbdc4b9f98e02edc685b to your computer and use it in GitHub Desktop.
Save simongeilfus/fbdc4b9f98e02edc685b to your computer and use it in GitHub Desktop.
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;
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;
}
}
{
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