The GroupIndex Template Library
Main Page | Class Hierarchy | Class List | File List | Class Members

wrapper.h

00001 #include <fstream>
00002 #include <cstdlib>
00003 #include <cstdio>
00004 
00005 #ifdef VISUALC_INCLUDES
00006  #ifndef ANSI_BRACES
00007   #define ANSI_BRACES
00008  #endif
00009  #ifndef ANSI_TYPENAME
00010   #define ANSI_TYPENAME
00011  #endif
00012 #else
00013  #ifndef ANSI_BRACES
00014   #define ANSI_BRACES <>
00015  #endif
00016  #ifndef ANSI_TYPENAME
00017   #define ANSI_TYPENAME typename
00018  #endif
00019 #endif
00020 
00021 namespace groupindex
00022 {
00023 
00028 template <class Group, class Set> 
00029 class operator_wrapper : public Group
00030 {
00031 
00032 public:
00033         
00034         inline operator_wrapper<Group,Set>() : Group() {}
00035 
00036         inline operator_wrapper<Group,Set>(const operator_wrapper<Group,Set>& g) : Group(g) {}
00037 
00038         inline operator_wrapper<Group,Set>(const Group& g) : Group(g) {}
00039 
00040         inline operator_wrapper<Group,Set>& operator*=(const operator_wrapper<Group,Set>& g)
00041         {
00042                 this->mult(g);
00043                 return *this;
00044         }
00045 
00046         inline bool operator!=(const operator_wrapper<Group,Set>& g)
00047         {
00048                 return !(this->isSimilar(g));
00049         }
00050 
00051         inline operator_wrapper<Group,Set>& operator*=(Set& s)
00052         {
00053                 this->operate(s);
00054                 return *this;
00055         }
00056 
00057         inline operator_wrapper<Group,Set>& operator!()
00058         {
00059                 this->invert();
00060                 return *this;
00061         }
00062 
00066         inline operator_wrapper<Group,Set>& operator/=(const operator_wrapper<Group,Set>& g)
00067         {
00068                 inverse = g;
00069                 this->mult(!inverse);
00070                 return *this;
00071         }
00072 
00076         inline operator_wrapper<Group,Set>& operator*(const operator_wrapper<Group,Set>& g)
00077         {
00078                 operator_wrapper<Group,Set> result = *this;
00079                 result*=g;
00080                 return result;
00081         }
00082 
00086         inline operator_wrapper<Group,Set>& operator/(const operator_wrapper<Group,Set>& g)
00087         {
00088                 inverse = g;
00089                 operator_wrapper<Group,Set> result = *this;
00090                 result*=!inverse;
00091                 return result;
00092         }
00093 
00094 };
00095 
00106 template <class T> 
00107 class fstream_wrapper : public T
00108 {
00109 
00110 public:
00111 
00112     fstream_wrapper() : T() {}
00113     fstream_wrapper(T t) : T(t) {}
00114     
00115     static long size()
00116     { 
00117         return sizeof(fstream_wrapper<T>);
00118     }
00119 
00120          operator T() const
00121     {
00122                  return this->T;
00123     }
00124     //friend std::ofstream& operator << ANSI_BRACES (std::ofstream& os, const fstream_wrapper<T>& t);
00125     //friend std::ifstream& operator >> ANSI_BRACES (std::ifstream& is, const fstream_wrapper<T>& t);
00126 
00127 };
00128 
00132 template <class T> 
00133 class stream_wrapper : public T
00134 {
00135 
00136 public:
00137         
00138         inline void writeToFile(FILE* stream) const 
00139         {
00140                 fwrite(this,sizeof(stream_wrapper<T>),1,stream);
00141         }
00142         inline void readFromFile(FILE* stream) const 
00143         {
00144                 fread(this,sizeof(stream_wrapper<T>),1,stream);
00145         }
00146 
00147 };
00148 
00149 template<class T>
00150 std::ofstream& operator<<(std::ofstream& os, const fstream_wrapper<T>& t)
00151 {
00152     os.write((char*)&t, sizeof(fstream_wrapper<T>));
00153     return os;
00154 }
00155 
00156 template<class T>
00157 std::ifstream& operator>>(std::ifstream& os, fstream_wrapper<T>& t)
00158 {
00159     os.read((char*)&t, sizeof(fstream_wrapper<T>));
00160         return os;
00161 }
00162 
00163 template<class T>
00164 std::fstream& operator>>(std::fstream& os, fstream_wrapper<T>& t)
00165 {
00166     os.read((char*)&t, sizeof(fstream_wrapper<T>));
00167         return os;
00168 }
00169 
00170 }
The GroupIndex-Template-Library
Universität Bonn, Institut für Informatik III, 2001