The Original CHomP Software
tabulate.h
Go to the documentation of this file.
1
3
15
16// Copyright (C) 1997-2020 by Pawel Pilarczyk.
17//
18// This file is part of my research software package. This is free software:
19// you can redistribute it and/or modify it under the terms of the GNU
20// General Public License as published by the Free Software Foundation,
21// either version 3 of the License, or (at your option) any later version.
22//
23// This software is distributed in the hope that it will be useful,
24// but WITHOUT ANY WARRANTY; without even the implied warranty of
25// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26// GNU General Public License for more details.
27//
28// You should have received a copy of the GNU General Public License
29// along with this software; see the file "license.txt". If not,
30// please, see <https://www.gnu.org/licenses/>.
31
32// Started in January 2002. Last revision: June 2, 2007.
33
34
35#ifndef _CHOMP_HOMOLOGY_TABULATE_H_
36#define _CHOMP_HOMOLOGY_TABULATE_H_
37
38#include "chomp/system/config.h"
40
41#include <iostream>
42#include <fstream>
43#include <cstdlib>
44
45namespace chomp {
46namespace homology {
47
51{
52public:
55
58
60 int read (int dim, const char *filename);
61
63 int write (int dim, const char *filename) const;
64
66 int compute (int dim);
67
71 int define (int dim, char *buffer);
72
75 const char *operator [] (int dim) const;
76
78 static int get (const char *table, int_t bitnumber);
79
81 static void set (char *table, int_t bitnumber);
82
83private:
85 static const int maxdim = 8;
86
88 char *tables [maxdim];
89
92
94 int size [maxdim];
95
96}; /* Tabulated */
97
98// --------------------------------------------------
99
100inline int Tabulated::define (int dim, char *buffer)
101{
102 if ((dim <= 0) || (dim >= maxdim))
103 return -1;
104 if (tables [dim] && deallocate [dim])
105 {
106 delete [] (tables [dim]);
107 deallocate [dim] = false;
108 }
109 tables [dim] = buffer;
110 return 0;
111} /* Tabulated::define */
112
113inline const char *Tabulated::operator [] (int dim) const
114{
115 if ((dim <= 0) || (dim >= maxdim))
116 return 0;
117 else
118 return tables [dim];
119} /* Tabulated::operator [] */
120
121inline int Tabulated::get (const char *table, int_t bitnumber)
122{
123 if (table [bitnumber >> 3] & (1 << (bitnumber & 0x07)))
124 return 1;
125 else
126 return 0;
127} /* Tabulated::get */
128
129inline void Tabulated::set (char *table, int_t bitnumber)
130{
131 table [bitnumber >> 3] |=
132 static_cast<char> (1 << (bitnumber & 0x07));
133 return;
134} /* Tabulated::set */
135
136// --------------------------------------------------
137
140extern Tabulated tabulated;
141
142
143} // namespace homology
144} // namespace chomp
145
146#endif // _CHOMP_HOMOLOGY_TABULATE_H_
147
149
A class for storing tabulated configurations of neighbors for various dimensions.
Definition: tabulate.h:51
int write(int dim, const char *filename) const
Writes tabulated configurations to a file.
int define(int dim, char *buffer)
Sets tabulated configuration bits to a given table.
Definition: tabulate.h:100
int read(int dim, const char *filename)
Reads tabulated configurations from a file.
int compute(int dim)
Computes tabulated configurations for a specific dimension.
~Tabulated()
The destructor.
int size[maxdim]
The size of the table in bytes for each dimension.
Definition: tabulate.h:94
const char * operator[](int dim) const
Retrieves the buffer allocated for the specific dimension or returns the null pointer if none.
Definition: tabulate.h:113
Tabulated()
The default constructor.
bool deallocate[maxdim]
Should the configuration tables be deallocated?
Definition: tabulate.h:91
char * tables[maxdim]
The tabulated configurations.
Definition: tabulate.h:88
static const int maxdim
The strict upper bound for the supported dimensions.
Definition: tabulate.h:85
static int get(const char *table, int_t bitnumber)
Retrieve the given bit from the given table.
Definition: tabulate.h:121
static void set(char *table, int_t bitnumber)
Sets the given bit in the given table.
Definition: tabulate.h:129
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115
Tabulated tabulated
The global instance of this class which stores tabulated configurations to use in the full cube reduc...
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51
This file contains some useful functions related to the text input/output procedures.