first commit
This commit is contained in:
60
include/framework/metafile/nml_object.h
Normal file
60
include/framework/metafile/nml_object.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NMETAOBJECT__
|
||||
#define __NMETAOBJECT__
|
||||
|
||||
|
||||
#include "metafile/nml.h"
|
||||
#include "reflection/c_refl.h"
|
||||
|
||||
|
||||
/*!
|
||||
@short Serialization helper.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
namespace GS {
|
||||
namespace NML {
|
||||
|
||||
template <class T> bool LoadFromFile(T &object, File &file)
|
||||
{
|
||||
return file.isEmpty() ? false : object.FromMetaTag(*file.GetTags()[0]);
|
||||
}
|
||||
template <class T> bool LoadFromFile(T &object, const char *path, bool verbose = true)
|
||||
{
|
||||
File file;
|
||||
file.name = path;
|
||||
if (!Parser::Load(path, file, verbose))
|
||||
return false;
|
||||
return LoadFromFile(object, file);
|
||||
}
|
||||
|
||||
template <class T> bool SaveToFile(T &object, File &file)
|
||||
{
|
||||
file.Clear();
|
||||
return file.AddRoot(object.AsMetaTag()) ? true : false;
|
||||
}
|
||||
template <class T> bool SaveToFile(T &object, const char *path)
|
||||
{
|
||||
File file;
|
||||
file.name = path;
|
||||
if (!SaveToFile(object, file))
|
||||
return false;
|
||||
|
||||
return Parser::Save(path, file);
|
||||
}
|
||||
|
||||
bool GenericObjectFromMetaTag(Tag &, void *obj, Reflection::Property *obj_prop);
|
||||
Tag *GenericObjectToMetaTag(Tag *, const void *obj, Reflection::Property *obj_prop);
|
||||
|
||||
bool GenericObjectFromMetaFile(const char *, void *obj, Reflection::Property *obj_prop, const char *root_name = 0);
|
||||
bool GenericObjectToMetaFile(const char *, const void *obj, Reflection::Property *obj_prop, const char *root_name = 0);
|
||||
|
||||
} // NML
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NMETAOBJECT__
|
||||
Reference in New Issue
Block a user