Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef VLXSerializer_INCLUDE_ONCE
00033 #define VLXSerializer_INCLUDE_ONCE
00034
00035 #include <vlCore/VLXRegistry.hpp>
00036 #include <vlCore/VLXValue.hpp>
00037 #include <vlCore/String.hpp>
00038 #include <string>
00039 #include <map>
00040
00041 namespace vl
00042 {
00043 class VirtualFile;
00045 class VLCORE_EXPORT VLXSerializer: public Object
00046 {
00047 VL_INSTRUMENT_CLASS(vl::VLXSerializer, Object)
00048
00049 public:
00050 typedef enum { NoError, ImportError, ExportError, ReadError, WriteError } EError;
00051
00052 public:
00053 VLXSerializer(): mError(NoError), mIDCounter(0)
00054 {
00055 setRegistry( defVLXRegistry() );
00056 }
00057
00058 const char* errorString() const;
00059
00060 bool saveVLT(const String& path, const Object* obj, bool start_fresh=true);
00061
00062 bool saveVLT(VirtualFile* file, const Object* obj, bool start_fresh=true);
00063
00064 bool saveVLB(const String& path, const Object* obj, bool start_fresh=true);
00065
00066 bool saveVLB(VirtualFile* file, const Object* obj, bool start_fresh=true);
00067
00068 ref<Object> loadVLT(const String& path, bool start_fresh=true);
00069
00070 ref<Object> loadVLT(VirtualFile* file, bool start_fresh=true);
00071
00072 ref<Object> loadVLB(const String& path, bool start_fresh=true);
00073
00074 ref<Object> loadVLB(VirtualFile* file, bool start_fresh=true);
00075
00076 Object* importVLX(const VLXStructure* st);
00077
00078 VLXStructure* exportVLX(const Object* obj);
00079
00080 bool canExport(const Object* obj) const;
00081
00082 bool canImport(const VLXStructure* st) const;
00083
00084 void registerImportedStructure(const VLXStructure* st, Object* obj);
00085
00086 void registerExportedObject(const Object* obj, VLXStructure* st);
00087
00088 Object* getImportedStructure(const VLXStructure* st);
00089
00090 VLXStructure* getExportedObject(const Object* obj);
00091
00093 VLXRegistry* registry() { return mRegistry.get(); }
00094
00096 const VLXRegistry* registry() const { return mRegistry.get(); }
00097
00099 void setRegistry(const VLXRegistry* registry) { mRegistry = registry; }
00100
00102 std::map< std::string, VLXValue >& metadata() { return mMetadata; }
00103
00105 const std::map< std::string, VLXValue >& metadata() const { return mMetadata; }
00106
00108 VLXValue* getMetadata(const char* key)
00109 {
00110 std::map< std::string, VLXValue >::iterator it = metadata().find(key);
00111 if (it == metadata().end())
00112 return NULL;
00113 else
00114 return &it->second;
00115 }
00116
00118 const VLXValue* getMetadata(const char* key) const
00119 {
00120 std::map< std::string, VLXValue >::const_iterator it = metadata().find(key);
00121 if (it == metadata().end())
00122 return NULL;
00123 else
00124 return &it->second;
00125 }
00126
00127 void reset()
00128 {
00129 mError = NoError;
00130 mIDCounter = 0;
00131 mImportedStructures.clear();
00132 mExportedObjects.clear();
00133 }
00134
00135 std::string generateID(const char* prefix);
00136
00138 void setError(EError err) { mError = err; }
00139
00141 EError error() const { return mError; }
00142
00143 void signalImportError(const String& str);
00144
00145 void signalExportError(const String& str);
00146
00148 void setDocumentURL(const String& location) { mDocumentURL = location; }
00149
00151 const String& documentURL() const { return mDocumentURL; }
00152
00154 void resolvePath(std::string& path);
00155
00158 void setDirective(const char* directive, const char* value) { mDirectives[directive] = value; }
00159
00161 void eraseDirective(const char* directive) { mDirectives.erase(directive); }
00162
00164 const std::string& directive(const char* directive) const
00165 {
00166 static const std::string no_directive = "NO_SUCH_DIRECTIVE";
00167 std::map<std::string, std::string>::const_iterator it = mDirectives.find(directive);
00168 if (it != mDirectives.end())
00169 return it->second;
00170 else
00171 return no_directive;
00172 }
00173
00175 bool hasDirective(const char* directive) { return mDirectives.find(directive) != mDirectives.end(); }
00176
00178 void eraseAllDirectives() { mDirectives.clear(); }
00179
00180 private:
00181 String mDocumentURL;
00182 std::map<std::string, std::string> mDirectives;
00183 EError mError;
00184 int mIDCounter;
00185 std::map< ref<VLXStructure>, ref<Object> > mImportedStructures;
00186 std::map< ref<Object>, ref<VLXStructure> > mExportedObjects;
00187 std::map< std::string, VLXValue > mMetadata;
00188 ref<VLXRegistry> mRegistry;
00189 };
00190 }
00191
00192 #endif