CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00023 // XMLStorage.cxx 00024 // Description: A storage in XML format for CLAM objects 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 // Private helper functions 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 } // namespace CLAM 00182 00183 00184 00690 #endif//_XMLStorage_hxx_ 00691