XMLStorage.hxx
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
00023
00024
00026
00027 #ifndef _XMLStorage_hxx_
00028 #define _XMLStorage_hxx_
00029
00030 #include "Storage.hxx"
00031 #include "XmlStorageErr.hxx"
00032 #include <iosfwd>
00033 #include <string>
00034
00035
00036 namespace CLAM
00037 {
00038
00039 class XMLable;
00040 class Component;
00041 class DomDocumentHandler;
00042
00043
00044 class XmlStorage : public Storage
00045 {
00046 DomDocumentHandler * _documentHandler;
00047 bool _lastWasContent;
00048 bool _useIndentation;
00049 std::string _errors;
00055
00056 public:
00057 XmlStorage();
00058 ~XmlStorage();
00059
00060 public:
00061 void Read(std::istream & is);
00062 void Create(const std::string & name);
00063 void WriteSelection(std::ostream & os);
00064 void WriteDocument(std::ostream & os);
00065 void DumpObject(const Component & component);
00066 void RestoreObject(Component & component);
00067
00081 void Select(const std::string & path);
00082
00089 void UseIndentation(bool useIndentation);
00090
00091
00097
00098 public:
00099
00103 static void Dump(const Component & obj, const std::string & rootName, std::ostream & os, bool indentate=true)
00104 {
00105 XmlStorage storage;
00106 storage.Create(rootName);
00107 storage.DumpObject(obj);
00108 storage.UseIndentation(indentate);
00109 storage.WriteDocument(os);
00110 }
00111
00115 static void Restore(Component & obj, std::istream & is)
00116 {
00117 XmlStorage storage;
00118 storage.Read(is);
00119 storage.RestoreObject(obj);
00120 }
00121
00125 static void RestoreFromFragment(Component & obj, const std::string & path, std::istream & is)
00126 {
00127 XmlStorage storage;
00128 storage.Read(is);
00129 storage.Select(path);
00130 storage.RestoreObject(obj);
00131 }
00132
00137 static void AppendToDocument(const Component & obj, const std::string & xpath, const std::string & filename);
00138
00142 static void Dump(const Component & obj, const std::string & rootName, const std::string & filename);
00143
00147 static void Restore(Component & obj, const std::string & filename);
00148
00149
00155
00156 public:
00161 void Store(const Storable & storable);
00166 bool Load(Storable & storable);
00167
00168
00169
00170 private:
00171 bool LoadContentAndChildren(XMLable* xmlable);
00172 void StoreContentAndChildren(const XMLable * xmlable);
00173 void StoreChildrenIfComponent(const XMLable * xmlable);
00174 void AddContentToElement(const std::string & content);
00175
00176 };
00177
00179 typedef XmlStorage XMLStorage;
00180
00181 }
00182
00183
00184
00690 #endif//_XMLStorage_hxx_
00691