00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: Reference.hpp,v 1.5 2007/06/09 10:37:07 delpinux Exp $ 00019 00020 #ifndef REFERENCE_HPP 00021 #define REFERENCE_HPP 00022 00023 #include <vector> 00034 class Reference 00035 { 00036 public: 00037 typedef std::vector<bool> Representation; 00038 00039 private: 00040 Reference::Representation __reference; 00041 00042 bool __insideDomain; 00043 00044 public: 00045 00046 const bool& insideDomain() const 00047 { 00048 return __insideDomain; 00049 } 00050 00051 bool& insideDomain() 00052 { 00053 return __insideDomain; 00054 } 00055 00056 void resize(const size_t i) 00057 { 00058 __reference.resize(i); 00059 } 00060 00061 inline size_t size() const 00062 { 00063 return __reference.size(); 00064 } 00065 00066 void set(const Representation& r) 00067 { 00068 ASSERT(r.size() == __reference.size()); 00069 __reference = r; 00070 } 00071 00072 bool isSet() const 00073 { 00074 for(Representation::const_iterator i = __reference.begin(); 00075 i != __reference.end(); ++i) { 00076 if (*i) { 00077 return true; 00078 } 00079 } 00080 return false; 00081 } 00082 00083 bool isSet(const Reference::Representation& r) const 00084 { 00085 ASSERT(r.size() == __reference.size()); 00086 00087 for (size_t i=0; i<r.size(); ++i) { 00088 if (r[i] && !__reference[i]) 00089 return false; 00090 } 00091 return true; 00092 } 00093 00094 bool operator == (const Reference& R) const 00095 { 00096 return (__reference == R.__reference); 00097 } 00098 00099 bool operator != (const Reference& R) const 00100 { 00101 return (__reference != R.__reference); 00102 } 00103 00104 const Reference& operator = (const size_t& i) 00105 { 00106 __reference[i] = true; 00107 return *this; 00108 } 00109 00110 const Reference& operator = (const Reference& R) 00111 { 00112 __reference = R.__reference; 00113 return *this; 00114 } 00115 00116 inline void set(const size_t& i, const bool& b) 00117 { 00118 ASSERT(i<__reference.size()); 00119 __reference[i] = b; 00120 } 00121 00122 00123 inline bool get(const size_t& i) const 00124 { 00125 ASSERT(i<__reference.size()); 00126 return __reference[i]; 00127 } 00128 00133 friend std::ostream& operator<<(std::ostream& os, 00134 const Reference& R) 00135 { 00136 size_t ref=0; 00137 for (size_t i = R.__reference.size()-1; i<R.__reference.size(); --i) { 00138 ref <<= 1; 00139 ref |= (R.__reference[i])?1:0; 00140 } 00141 00142 os << ref; 00143 return os; 00144 } 00145 00146 00147 Reference() 00148 { 00149 ; 00150 } 00151 00152 Reference(const Reference& R) 00153 : __reference(R.__reference) 00154 { 00155 ; 00156 } 00157 00158 Reference(const size_t size) 00159 { 00160 __reference.resize(size); 00161 } 00162 00163 ~Reference() 00164 { 00165 ; 00166 } 00167 }; 00168 00169 #endif // REFERENCE_HPP 00170
1.5.6