rasdaman complete source
structtype.hh
Go to the documentation of this file.
1 // -*-C++-*- (for Emacs)
2 
3 /*
4 * This file is part of rasdaman community.
5 *
6 * Rasdaman community is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Rasdaman community is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
20 rasdaman GmbH.
21 *
22 * For more information please see <http://www.rasdaman.org>
23 * or contact Peter Baumann via <baumann@rasdaman.com>.
24 */
25 /*************************************************************
26  *
27  *
28  * PURPOSE:
29  * The StructType class is the superclass for all classes
30  * describing the type of a cell
31  *
32  *
33  * COMMENTS:
34  *
35  ************************************************************/
36 
37 #ifndef _STRUCTTYPE_HH_
38 #define _STRUCTTYPE_HH_
39 
40 #include <iostream>
41 #include <vector>
42 
43 #include "compositetype.hh"
44 #include "catalogmgr/ops.hh"
45 
46 class BaseType;
47 
48 //@ManMemo: Module: {\bf relcatalogif}.
49 
50 /*@Doc:
51 StructType is the base type used for user defined structures. It
52 stores the names and BaseTypes of the elements. The size of a
53 StructType in chars depends on the elements.
54 
55 StructType now uses alignment for structures with elements of
56 different sizes. One byte types are aligned to one byte, two byte
57 types to two, all other types to four. The Size is padded to 4 byte
58 alignment except for types with only chars (one byte alignment) or
59 type with only shorts (two byte alignment). Structs as elements of
60 structs are aligned with the minimum byte alignment needed for the
61 struct.
62 
63 */
64 
68 class StructType : public CompositeType
69 {
70  // friend ostream& operator << (ostream& stream, StructType& b);
71 
72 public:
73  virtual void printCell(ostream& stream, const char* cell) const;
74 
75  virtual char* getTypeStructure() const;
76 
78  unsigned int addElement(const char* elemName, const char* elemType);
79 
81  unsigned int addElement(const char* elemName, const BaseType* elemType);
82 
84  unsigned int getOffset(const char* elemName) const;
85 
87  unsigned int getOffset(unsigned int num) const;
88 
90  const BaseType* getElemType(const char* elemName) const;
91 
93  const char* const getElemName(unsigned int num) const;
94 
96  const BaseType* getElemType(unsigned int num) const;
97 
99  unsigned int getNumElems() const;
100 
102  unsigned int getAlignment() const;
103 
105  int contains(const StructType* aStruct) const;
106 
107  StructType(const OId& structtypeid) throw (r_Error);
108 
110  StructType();
111 
113  StructType(const char* newTypeName, unsigned int numElem );
114 
116  StructType( const StructType& old );
117 
119  StructType& operator=( const StructType& old );
120 
122  virtual ~StructType();
123 
124  virtual int compatibleWith(const Type* aType) const;
125 
126  virtual r_Bytes getMemorySize() const;
127 
128 private:
129  // those inherited from BaseType aren't useful at all for StructType
130  // made them private to preven calling them
131  virtual r_ULong* convertToCULong(const char* cell, r_ULong* value) const;
132  virtual char* makeFromCULong(char* cell, const r_ULong* value) const;
133  virtual r_Long* convertToCLong(const char* cell, r_Long* value) const;
134  virtual char* makeFromCLong(char* cell, const r_Long* value) const;
135  virtual double* convertToCDouble(const char* cell, double* value) const;
136  virtual char* makeFromCDouble(char* cell, const double* value) const;
137 
138 
139 protected:
140 
141  virtual void insertInDb() throw (r_Error);
142 
143  virtual void deleteFromDb() throw (r_Error);
144 
145  virtual void readFromDb() throw (r_Error);
146 
147  // moves back one step all elements all elements behind pos
148  void moveBack(int pos);
149 
150  // calculates and sets current size of type with alignment
151  void calcSize();
152 
154  std::vector< const BaseType* > elements;
155 
157  std::vector< char* > elementNames;
158 
160  std::vector< unsigned int > elementOffsets;
161 
163  unsigned int numElems;
164 
166  unsigned int align;
167 
171  unsigned int addElementPriv(const char* elemName, const BaseType* elemType);
172 };
173 
174 #include "structtype.icc"
175 
176 #endif
virtual char * getTypeStructure() const
returns the structure of the type as a C string.
unsigned int addElementPriv(const char *elemName, const BaseType *elemType)
virtual void insertInDb()
unsigned int numElems
The number of elements.
Definition: structtype.hh:163
std::vector< unsigned int > elementOffsets
Array containing offsets to elements.
Definition: structtype.hh:160
virtual void readFromDb()
const char *const getElemName(unsigned int num) const
get name of an element by number of element (0 based).
const BaseType * getElemType(const char *elemName) const
get type of an element by name of element.
StructType & operator=(const StructType &old)
assignment operator.
Definition: oidif.hh:67
unsigned int align
Alignment needed for structure if embedded in other structures.
Definition: structtype.hh:166
Definition: compositetype.hh:54
unsigned int getNumElems() const
get number of elements.
Definition: structtype.hh:68
void moveBack(int pos)
void calcSize()
virtual int compatibleWith(const Type *aType) const
virtual void deleteFromDb()
virtual void printCell(ostream &stream, const char *cell) const
unsigned int getAlignment() const
get alignment needed for structure to be embedded in another structure.
Definition: relcatalogif/basetype.hh:66
StructType()
default constructor, sets type name to "".
virtual ~StructType()
virtual destructor.
Definition: relcatalogif/type.hh:68
int contains(const StructType *aStruct) const
checks if a certain StructType is contained in this StructType
std::vector< const BaseType * > elements
Array containing references to base types of elements.
Definition: structtype.hh:154
virtual r_Bytes getMemorySize() const
std::vector< char * > elementNames
Array containing names of elements.
Definition: structtype.hh:157
unsigned int addElement(const char *elemName, const char *elemType)
add new element to struct
unsigned int getOffset(const char *elemName) const
get offset for an element by name of element.