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__expr_h__ 00021 #define __loaded__expr_h__ 00022 using namespace std; 00023 #line 1 "expr.h++" 00024 #include "reference-count.h" 00025 namespace BorgIv{ 00026 class ExpData; 00027 00028 class Key 00029 { 00030 public: 00031 virtual ~Key() 00032 { 00033 }; 00034 }; 00035 00050 class Exp: public Smart<ExpData>, public Key 00051 { 00052 public: 00053 Exp(); 00054 Exp(ExpData * d); 00058 Exp(ExpData& scratch); 00067 Exp operator[](Key* key) const; 00071 template <class TargetType> 00072 operator const TargetType() const 00073 { 00074 return dynamic_cast<const TargetType>(ptr); 00075 } 00076 00080 void operator =(ExpData* data) 00081 { 00082 Smart<ExpData>::operator=((const Smart<ExpData>)data); 00083 } 00084 }; 00085 00094 class ExpData: public ReferenceCount 00095 { 00096 protected: 00097 friend class Exp; 00102 virtual ExpData* new_copy() const = 0; 00103 virtual Exp operator[](Key* key) const = 0; 00108 ExpData* copy_if_necessary() 00109 { 00110 if (reference_count==0) return new_copy(); 00111 return this; 00112 } 00113 }; 00114 00115 Exp::Exp(ExpData * d): Smart<ExpData>(d->copy_if_necessary()) 00116 { 00117 assert(d); 00118 } 00119 00120 Exp::Exp(ExpData& scratch): Smart<ExpData>(scratch.copy_if_necessary()) 00121 { 00122 } 00123 00124 Exp Exp::operator[](Key* key) const 00125 { 00126 return ptr[0][key]; 00127 } 00128 00129 Exp::Exp(): Smart<ExpData>() 00130 { 00131 }; 00132 00133 } // end namespace 00134 #endif // __loaded__expr_h__