00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 by the OpenStructure authors 00005 // Copyright (C) 2003-2010 by the IPLT authors 00006 // 00007 // This library is free software; you can redistribute it and/or modify it under 00008 // the terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 3.0 of the License, or (at your option) 00010 // any later version. 00011 // This library is distributed in the hope that it will be useful, but WITHOUT 00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00014 // details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this library; if not, write to the Free Software Foundation, Inc., 00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 //------------------------------------------------------------------------------ 00020 00021 /* 00022 low level info implementation 00023 00024 Author: Ansgar Philippsen 00025 */ 00026 00027 #ifndef OST_DATA_INFO_IMPL_H 00028 #define OST_DATA_INFO_IMPL_H 00029 00030 #include <ost/message.hh> 00031 #include <utility> 00032 #include <vector> 00033 #include <iostream> 00034 00035 #include <QDomElement> 00036 #include <QDomDocument> 00037 #include <QDomAttr> 00038 #include <QDomText> 00039 00040 #include <ost/base.hh> 00041 #include <ost/geom/geom.hh> 00042 00043 #include <ost/ptr_observer.hh> 00044 00045 #include "info_impl_fw.hh" 00046 #include "item_type.hh" 00047 00048 namespace ost { namespace info { namespace detail { 00049 00050 typedef std::vector<ElePtr> EleList; 00051 /* 00052 wraps a DomElement, to be used by the high level item and group class 00053 */ 00054 class EleImpl { 00055 public: 00056 EleImpl(const QDomElement& e); 00057 00058 // tag name access 00059 String GetName() const; 00060 void SetName(const String& n); 00061 00062 // get full path 00063 String GetPath() const; 00064 00065 00066 // attribute access 00067 void SetAttribute(const String& name, const String& value); 00068 String GetAttribute(const String& name) const; 00069 bool HasAttribute(const String& name) const; 00070 void RemoveAttribute(const String& name); 00071 00072 std::vector<String> GetAttributeList() const; 00073 00074 String GetTextData() const; 00075 void SetTextData(const String& td); 00076 00077 String GetComment() const; 00078 00082 EleList GetSubs(const String& name) const; 00083 00086 ElePtr GetSub(const String& name) const; 00087 ElePtr CreateSub(const String& name); 00088 bool HasSub(const String& name) const; 00089 00090 void RemoveSub(const String& name); 00091 00092 void RemoveSub(const ElePtr& ele); 00093 00094 QDomElement& GetElement(); 00095 const QDomElement& GetElement() const; 00096 00097 InfoImpl& GetRoot(); 00098 InfoImpl& GetRoot() const; 00099 00100 std::vector<ElePtr> GetSubList() const; 00101 00102 ElePtr GetParent() const; 00103 00104 bool operator==(const EleImpl& ref) const; 00105 00106 Type GetType() const; 00107 void SetType(Type t); 00108 00109 void SetNewType(int t); 00110 00111 void SetStringRepr(const String& v, bool settype); 00112 String GetStringRepr() const; 00113 void SetIntRepr(int repr); 00114 int GetIntRepr() const; 00115 void SetFloatRepr(float repr); 00116 float GetFloatRepr() const; 00117 void SetBoolRepr(bool repr); 00118 bool GetBoolRepr() const; 00119 void SetVecRepr(const geom::Vec3& repr); 00120 geom::Vec3 GetVecRepr() const; 00121 00122 private: 00123 QDomElement ele_; 00124 00125 Type type_; 00126 00127 String String_repr_; 00128 int int_repr_; 00129 float float_repr_; 00130 bool bool_repr_; 00131 geom::Vec3 vec_repr_; 00132 }; 00133 00134 00135 class InfoImpl { 00136 public: 00137 InfoImpl(); 00138 InfoImpl(const String& file); 00139 InfoImpl(bool dummy,const String& text); 00140 00141 RootPtr Copy() const; 00142 00143 void Import(const String& file); 00144 void Export(const String& file); 00145 00146 EleImpl Root(); 00147 00148 RootPtrList& DefList() {return def_list_;} 00149 const RootPtrList& DefList() const {return def_list_;} 00150 00151 QDomDocument& GetDocument() {return document_;} 00152 const QDomDocument& GetDocument() const {return document_;} 00153 00154 private: 00155 QDomDocument document_; 00156 00157 RootPtrList def_list_; 00158 }; 00159 00160 }}} // ns 00161 00162 #endif