00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #ifndef __loaded__data_cpp__
00021 #define __loaded__data_cpp__
00022 using namespace std;
00023 #line 1 "data.c++"
00024 #include "data.h"
00025 #include "null.h"
00026 #include "numbers.h"
00027 #include "array.h"
00028 #include "symbol.h"
00029 #include "data-string.h"
00030 #include "data-token.h"
00031 
00032 
00033 
00034 
00035 DataClass* DataClass::memory_copy() const
00036 {
00037   if (allocation_count)
00038     {
00039       
00040       int * ac = (int*)(void*)&allocation_count;
00041       (*ac)++;
00042       return (DataClass*)(void*)this;
00043     }
00044   else
00045     {
00046       DataClass* answer = shallow_copy();
00047       answer->allocation_count = 1;
00048       
00049       return answer;
00050     }
00051 };
00052 
00053 void DataClass::memory_release()
00054 {
00055   
00056   
00057   assert(allocation_count>0);
00058   if (--allocation_count==0)
00059     {
00060       
00061       delete this;
00062     }
00063 }
00064 
00065 Data DataClass::getField(QString)
00066 {  
00067    QString s = type_name() + " does not have a getField operation";
00068    printf("%s\n",s.toAscii().data());
00069    assert(0);
00070    _exit(100);
00071  }
00072 
00073 void DataClass::setField(QString, Data d)
00074 {  
00075    QString s = type_name() + " does not have a setField operation";
00076    printf("%s\n",s.toAscii().data());
00077 }
00078 
00079 void Data::type_error(QString expected) const
00080 {
00081   const char * a;
00082   const char * b;
00083 #if QT_VERSION > 0x040000
00084   a = strdup(expected.toAscii().data());
00085   b = strdup(type().toAscii().data());
00086 #else
00087   a = strdup(expected.ascii());
00088   b = strdup(type().ascii());
00089 #endif
00090   printf("Expected %s, got %s\n",a,b);
00091   assert(0);
00092   _exit(0);
00093 }
00094 
00095 Data::Data()
00096 {
00097   content = new Null();
00098   content->allocation_count = 1;
00099 }
00100 
00101 Data::Data(const Data& other)
00102 {
00103   assert(other.content);
00104   content = other.content->memory_copy();
00105 }
00106 
00107 Data::Data(const DataClass & blah)
00108 {
00109   content = blah.memory_copy();
00110 }
00111 
00112 Data::~Data()
00113 {
00114   assert(content);
00115   
00116   content->memory_release();
00117   content = NULL;
00118 }
00119 
00120 Data& Data::operator = (const Data& other)
00121 {
00122   if (content!=other.content)
00123     {
00124       content -> memory_release();
00125       content =  other.content->memory_copy();
00126     }
00127   return *this;
00128 }
00129 
00130 bool Data::isNull() const
00131 {
00132   return typeid(*content)==typeid(Null);
00133 }
00134 
00135 #define ARRAY_TYPE(T,D) \
00136 Data::operator Array<T,D>() const \
00137 { \
00138   if (typeid(*content)!=typeid(Array<T,D>)) \
00139     type_error("Array<"#T ","#D ">"); \
00140   return *(Array<T,D>*)content; \
00141 }
00142 ARRAY_TYPES
00143 #undef ARRAY_TYPE
00144 
00145 #define BASIC_TYPE(T,N,C) \
00146 Data::operator C() const \
00147 {\
00148   if (typeid(*content)!=typeid(C)) \
00149     type_error(#C); \
00150   return *(C*)content; \
00151 }
00152 BASIC_TYPES;
00153 #undef BASIC_TYPE
00154 
00155 Data::operator Symbol() const
00156 {
00157   if (typeid(*content)!=typeid(Symbol))
00158     type_error("Symbol");
00159   return *(Symbol*)content;
00160 }
00161 
00162 Data::operator String() const
00163 {
00164   assert(typeid(*content)==typeid(String));
00165   return *(String*)content;
00166 }
00167 
00168 Data::operator Token() const
00169 {
00170   if (typeid(*content)!=typeid(Token))
00171     type_error("Token");
00172   return *(Token*)content;
00173 }
00174 
00175 void Data::visit(DataVisitor& v) 
00176 {
00177   content->visit(v);
00178 };
00179 
00180 Data Data::getField(QString s)
00181 {
00182    assert(content);
00183    return content->getField(s);
00184 }
00185 
00186 void Data::setField(QString s, Data v)
00187 {
00188    assert(content);
00189    content->setField(s,v);
00190 }
00191 #endif // __loaded__data_cpp__