00001 /**** 00002 Hierarchical Data Objects 00003 Copyright (C) 2005-2010 Werner Van Belle 00004 http://flow.yellowcouch.org/data/ 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 #ifndef __loaded__data_h__ 00021 #define __loaded__data_h__ 00022 using namespace std; 00023 #line 1 "data.h++" 00024 #include <Qt/qstring.h> 00025 #include <assert.h> 00026 #include "data-version.h" 00027 #include "types.h" 00028 00029 #ifndef WINDOWS 00030 #ifndef LINUX 00031 00032 #ifdef Q_OS_WIN32 00033 #define WINDOWS 00034 #endif 00035 00036 #ifdef Q_OS_LINUX 00037 #define LINUX 00038 #endif 00039 00040 #endif 00041 #endif 00042 00043 #ifndef WINDOWS 00044 #ifndef LINUX 00045 #error "Must define either LINUX or WINDOWS" 00046 #endif 00047 #endif 00048 00094 //=============================================================== 00095 // Data 00096 //=============================================================== 00097 00098 //--------------------------------------------------------------- 00099 // Data 00100 //--------------------------------------------------------------- 00101 00112 class DataClass 00113 { 00114 private: 00115 friend class Data; 00122 int allocation_count; 00123 00132 DataClass* memory_copy() const; 00133 00141 void memory_release(); 00142 00143 protected: 00148 virtual DataClass* shallow_copy() const = 0; 00149 virtual QString type_name() const = 0; 00153 virtual Data getField(QString ref); 00154 virtual void setField(QString, Data v); 00155 public: 00156 00160 DataClass() : allocation_count(0) 00161 { 00162 }; 00163 00164 DataClass(const DataClass&) : allocation_count(0) 00165 { 00166 }; 00167 00168 DataClass & operator = (const DataClass&) 00169 { 00170 return *this; 00171 }; 00172 00173 DataClass(const Data& d); 00174 virtual ~DataClass() 00175 { 00176 assert(allocation_count==0); 00177 }; 00178 protected: 00179 friend class DataVisitor; 00180 virtual void visit(DataVisitor& v) = 0; 00181 }; 00182 00202 class Data 00203 { 00204 protected: 00205 friend class DataClass; 00206 00213 DataClass * content; 00214 00219 void type_error(QString expected) const; 00220 public: 00224 Data(); 00225 00232 Data(const Data& data); 00233 00240 Data(const DataClass & blah); 00241 00247 Data & operator =(const Data& from); 00248 00252 ~Data(); 00253 public: 00254 00258 QString type() const 00259 { 00260 return content->type_name(); 00261 }; 00262 00267 bool isNull() const; 00268 00274 operator Symbol() const; 00275 00281 operator Token() const; 00282 00288 operator String() const; 00289 00290 #define BASIC_TYPE(T,N,C) \ 00291 operator C() const; 00292 BASIC_TYPES; 00293 #undef BASIC_TYPE 00294 00295 #define ARRAY_TYPE(T,D) \ 00296 operator Array<T,D>() const; 00297 ARRAY_TYPES; 00298 #undef ARRAY_TYPE 00299 00304 Data & operator +=(const Data &) 00305 { 00306 assert(0); 00307 }; 00308 00313 Data & operator -=(const Data &) 00314 { 00315 assert(0); 00316 }; 00317 00322 Data & operator /=(const Data &) 00323 { 00324 assert(0); 00325 }; 00326 00331 Data & operator *=(const Data &) 00332 { 00333 assert(0); 00334 }; 00335 00341 bool & operator !=(const Data &) 00342 { 00343 assert(0); 00344 }; 00345 00349 Data getField(QString s); 00350 00354 void setField(QString s, Data v); 00355 00361 bool & operator ==(const Data &) 00362 { 00363 assert(0); 00364 }; 00365 protected: 00366 friend class DataVisitor; 00367 void visit(DataVisitor& v); 00368 }; 00369 #endif // __loaded__data_h__