tabulate.h

Go to the documentation of this file.
00001 
00002 
00003 
00015 
00016 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
00017 //
00018 // This file is part of the Homology Library.  This library is free software;
00019 // you can redistribute it and/or modify it under the terms of the GNU
00020 // General Public License as published by the Free Software Foundation;
00021 // either version 2 of the License, or (at your option) any later version.
00022 //
00023 // This library is distributed in the hope that it will be useful,
00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 // GNU General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License along
00029 // with this software; see the file "license.txt".  If not, write to the
00030 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00031 // MA 02111-1307, USA.
00032 
00033 // Started in January 2002. Last revision: June 2, 2007.
00034 
00035 
00036 #ifndef _CHOMP_HOMOLOGY_TABULATE_H_
00037 #define _CHOMP_HOMOLOGY_TABULATE_H_
00038 
00039 #include "chomp/system/config.h"
00040 #include "chomp/system/textfile.h"
00041 
00042 #include <iostream>
00043 #include <fstream>
00044 #include <cstdlib>
00045 
00046 namespace chomp {
00047 namespace homology {
00048 
00051 class Tabulated
00052 {
00053 public:
00055         Tabulated ();
00056 
00058         ~Tabulated ();
00059 
00061         int read (int dim, const char *filename);
00062 
00064         int write (int dim, const char *filename) const;
00065 
00067         int compute (int dim);
00068 
00072         int define (int dim, char *buffer);
00073 
00076         const char *operator [] (int dim) const;
00077 
00079         static int get (const char *table, int_t bitnumber);
00080 
00082         static void set (char *table, int_t bitnumber);
00083 
00084 private:
00086         static const int maxdim = 8;
00087 
00089         char *tables [maxdim];
00090 
00092         bool deallocate [maxdim];
00093 
00095         int size [maxdim];
00096         
00097 }; /* Tabulated */
00098 
00099 // --------------------------------------------------
00100 
00101 inline int Tabulated::define (int dim, char *buffer)
00102 {
00103         if ((dim <= 0) || (dim >= maxdim))
00104                 return -1;
00105         if (tables [dim] && deallocate [dim])
00106         {
00107                 delete [] (tables [dim]);
00108                 deallocate [dim] = false;
00109         }
00110         tables [dim] = buffer;
00111         return 0;
00112 } /* Tabulated::define */
00113 
00114 inline const char *Tabulated::operator [] (int dim) const
00115 {
00116         if ((dim <= 0) || (dim >= maxdim))
00117                 return 0;
00118         else
00119                 return tables [dim];
00120 } /* Tabulated::operator [] */
00121 
00122 inline int Tabulated::get (const char *table, int_t bitnumber)
00123 {
00124         if (table [bitnumber >> 3] & (1 << (bitnumber & 0x07)))
00125                 return 1;
00126         else
00127                 return 0;
00128 } /* Tabulated::get */
00129 
00130 inline void Tabulated::set (char *table, int_t bitnumber)
00131 {
00132         table [bitnumber >> 3] |=
00133                 static_cast<char> (1 << (bitnumber & 0x07));
00134         return;
00135 } /* Tabulated::set */
00136 
00137 // --------------------------------------------------
00138 
00141 extern Tabulated tabulated;
00142 
00143 
00144 } // namespace homology
00145 } // namespace chomp
00146 
00147 #endif // _CHOMP_HOMOLOGY_TABULATE_H_
00148 
00150