-
Notifications
You must be signed in to change notification settings - Fork 2
/
GridTypes.h
59 lines (51 loc) · 1.44 KB
/
GridTypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef GRID_TYPES_H
#define GRID_TYPES_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/**
* \global
* This file describes different object that can be stored in a VoxSpace
* Such an objcet must have an operator=, and functions save,load,print
* **/
/**
* \class GenericCell
* A generic Cell to contains anything
* **/
template <class C>
class GenericCell {
public:
C value;
GenericCell() {}
GenericCell(const C & v) : value(v) {}
const GenericCell & operator=(const C & v) {value = v;return *this;}
const GenericCell & operator=(const GenericCell & v) {value = v.value;return *this;}
bool load(FILE * fp) {return fread(&value,sizeof(C),1,fp)==1;}
bool save(FILE * fp) const {return fwrite(&value,sizeof(C),1,fp)==1;}
void print(FILE * fp) const {fprintf(fp,"%p ",&value);}
};
/**
* \class IntegerCell
* A Cell that contains an integer value
* **/
template <class C>
class IntegerCell : public GenericCell<C>
{
public :
IntegerCell() : GenericCell<C>() {}
IntegerCell(const C & v) : GenericCell<C>(v) {}
void print(FILE * fp) const {fprintf(fp,"%d ",GenericCell<C>::value);}
};
/**
* \class FloatingCell
* A Cell that contains floating point value
* **/
template <class C>
class FloatingCell : public GenericCell<C>
{
public:
FloatingCell() : GenericCell<C>() {}
FloatingCell(const C & v) : GenericCell<C>(v) {}
void print(FILE * fp) const {fprintf(fp,"%le ",GenericCell<C>::value);}
};
#endif // GRID_TYPES_H