summaryrefslogtreecommitdiffstats
path: root/raslib/attribute.cc
blob: 6456810a83dff3f7db3df80f0e49ca1e4d2479b7 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/

static const char rcsid[] = "@(#) raslib, r_Attribute: $Header: /home/rasdev/CVS-repository/rasdaman/raslib/attribute.cc,v 1.11 2003/12/27 23:01:21 rasdev Exp $";

#include "raslib/attribute.hh"
#include "raslib/basetype.hh" 
#include "raslib/structuretype.hh" 
#include "raslib/rminit.hh"
#include "raslib/error.hh"

r_Attribute::r_Attribute() 
	:	r_Property(),
		localOffset(0),
		globalOffset(0)
	{
	}

r_Attribute::r_Attribute(const char* newTypeName, const r_Base_Type& newType) 
	:	r_Property(newTypeName, newType),
		localOffset(0),
		globalOffset(0) 
	{
	}

r_Attribute::r_Attribute(const r_Attribute& oldObj) 
	:	r_Property(oldObj) ,
		localOffset(oldObj.localOffset),
		globalOffset(oldObj.globalOffset) 
	{
	}

const r_Attribute& 
r_Attribute::operator=(const r_Attribute& oldObj) 
	{
	// Gracefully handle self assignment
	if (this != &oldObj)
		{
		r_Property::operator=(oldObj) ;
		localOffset = oldObj.localOffset;
		globalOffset = oldObj.globalOffset;
		}

	return *this;
	}

r_Attribute::~r_Attribute() 
	{
	}

r_Bytes
r_Attribute::offset() const
	{
	return localOffset;
	}

void
r_Attribute::set_offset(r_Bytes newOffset) 
	{
	localOffset = newOffset;
	}

r_Bytes
r_Attribute::global_offset() const
	{
	return globalOffset;
	}

void
r_Attribute::set_global_offset(r_Bytes newOffset) 
	{
	globalOffset = newOffset;
	}

void 
r_Attribute::print_status(std::ostream& s) const
	{
	type_of().print_status(s);
	s << " " << name() << std::flush;
	}



r_Attribute 
r_Attribute::operator[](unsigned int number) const throw(r_Error) 
	{
	if (type_of().type_id() != r_Type::STRUCTURETYPE) 
		{
		RMInit::logOut << "r_Attribute::operator[](" << number << ") not a struct type" << endl;
		throw r_Error(r_Error::r_Error_TypeInvalid) ;
		}
		
	const r_Structure_Type& structValue = (const r_Structure_Type&)type_of();

	return structValue[number];
	}



r_Boolean 
r_Attribute::get_boolean(const char* cell) const throw(r_Error) 
	{
	if (type_of().type_id() != r_Type::BOOL) 
		{
		RMInit::logOut << "r_Attribute::get_boolean(data) not a boolean" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Boolean*) (cell+globalOffset) ) ;
	}



r_Char	 
r_Attribute::get_char(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::CHAR) 
		{
		RMInit::logOut << "r_Attribute::get_char(data) not a char" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Char*) (cell+globalOffset) ) ;
	}



r_Octet	 
r_Attribute::get_octet(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::OCTET) 
		{
		RMInit::logOut << "r_Attribute::get_octet(data) not a octet" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Octet*) (cell+globalOffset) ) ;
	}



r_Short	 
r_Attribute::get_short(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::SHORT) 
		{
		RMInit::logOut << "r_Attribute::get_short(data) not a short" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Short*) (cell+globalOffset) ) ;
	}



r_UShort	
r_Attribute::get_ushort(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::USHORT) 
		{
		RMInit::logOut << "r_Attribute::get_ushort(data) not a ushort" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_UShort*) (cell+globalOffset) ) ;
	}



r_Long		
r_Attribute::get_long(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::LONG) 
		{
		RMInit::logOut << "r_Attribute::get_long(data) not a long" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Long*) (cell+globalOffset) ) ;
	}



r_ULong	 
r_Attribute::get_ulong(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::ULONG) 
		{
		RMInit::logOut << "r_Attribute::get_ulong(data) not a ulong" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_ULong*) (cell+globalOffset) ) ;
	}



r_Float	 
r_Attribute::get_float(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::FLOAT) 
		{
		RMInit::logOut << "r_Attribute::get_float(data) not a float" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Float*) (cell+globalOffset) ) ;
	}



r_Double	
r_Attribute::get_double(const char* cell) const throw(r_Error) 
	{
	if (type_of() .type_id() != r_Type::DOUBLE) 
		{
		RMInit::logOut << "r_Attribute::get_double(data) not a double" << endl;
		r_Error err(r_Error::r_Error_TypeInvalid) ;
		throw(err) ;		 
		}

	return *((r_Double*) (cell+globalOffset) ) ;
	}

std::ostream &operator<<( std::ostream &str, const r_Attribute &type )
{
  type.print_status(str);
  return str;
}