Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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