Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlCore/VLXSerializer.hpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
00005 /*                                                                                    */
00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
00007 /*  All rights reserved.                                                              */
00008 /*                                                                                    */
00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
00010 /*  are permitted provided that the following conditions are met:                     */
00011 /*                                                                                    */
00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
00013 /*  list of conditions and the following disclaimer.                                  */
00014 /*                                                                                    */
00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
00017 /*  other materials provided with the distribution.                                   */
00018 /*                                                                                    */
00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
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; // structure --> object
00186     std::map< ref<Object>, ref<VLXStructure> > mExportedObjects;    // object --> structure
00187     std::map< std::string, VLXValue > mMetadata; // metadata to import or to export
00188     ref<VLXRegistry> mRegistry;
00189   };
00190 }
00191 
00192 #endif

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:33.
Permission is granted to use this page to write and publish articles regarding Visualization Library.