summaryrefslogtreecommitdiffstats
path: root/qlparser/qtatomicdata.cc
blob: a8b12f86d9cb9b858cb1db786e4c1d6c98297f35 (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
/*
* 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>.
*/
/*************************************************************
 *
 *
 * COMMENTS:
 *
 ************************************************************/

static const char rcsid[] = "@(#)qlparser, QtAtomicData: $Header: /home/rasdev/CVS-repository/rasdaman/qlparser/qtatomicdata.cc,v 1.18 2003/12/27 20:51:28 rasdev Exp $";

#include "qlparser/qtatomicdata.hh"
#include "relcatalogif/basetype.hh"
#include "relcatalogif/alltypes.hh"

#include <iostream>
#ifndef CPPSTDLIB
#include <ospace/string.h> // STL<ToolKit>
#else
#include <string>
using namespace std;
#endif

#include <iostream>

#include "raslib/rmdebug.hh"


QtAtomicData::QtAtomicData()
  : QtScalarData()
{
}



QtAtomicData::QtAtomicData( r_Long value, unsigned short byteLength )
  : QtScalarData()
{
  switch( byteLength )
  {
    case 1: valueType = TypeFactory::mapType("Octet");  break;
    case 2: valueType = TypeFactory::mapType("Short");  break;
    case 4: valueType = TypeFactory::mapType("Long");   break;

    default:
      RMInit::logOut << "Error: QtAtomicData::QtAtomicData() - signed integer value with length "
                     << byteLength << " is not supported." << endl;
  }

  if( valueType )
  {
    r_Long temp = value;
    valueBuffer = new char[ valueType->getSize() ];
    valueType->makeFromCLong( valueBuffer, &temp ); 
  } 
}


QtAtomicData::QtAtomicData( r_ULong value, unsigned short byteLength )
  : QtScalarData()
{
  switch( byteLength )
  {
    case 1: valueType = TypeFactory::mapType("Char");   break;
    case 2: valueType = TypeFactory::mapType("UShort"); break;
    case 4: valueType = TypeFactory::mapType("ULong");  break;

    default:
      RMInit::logOut << "Error: QtAtomicData::QtAtomicData() - unsigned integer value with length "
                     << byteLength << " is not supported." << endl;
  }


  if( valueType )
  {
    r_ULong temp = value;
    valueBuffer = new char[ valueType->getSize() ];
    valueType->makeFromCULong( valueBuffer, &temp ); 
  } 
}



QtAtomicData::QtAtomicData( bool value )
  : QtScalarData()
{
  r_ULong valueULong = (r_ULong)value;

  valueType   = TypeFactory::mapType("Bool");
  valueBuffer = new char[ valueType->getSize() ];
  valueType->makeFromCULong( valueBuffer, &valueULong ); 
}



QtAtomicData::QtAtomicData( double value, unsigned short byteLength )
  : QtScalarData()
{
  switch( byteLength )
  {
    case 4: valueType = TypeFactory::mapType("Float");  break;
    case 8: valueType = TypeFactory::mapType("Double"); break;

    default:
      RMInit::logOut << "Error: QtAtomicData::QtAtomicData() - float value with length "
                     << byteLength << " is not supported." << endl;
  }


  if( valueType )
  {
    valueBuffer = new char[ valueType->getSize() ];
    valueType->makeFromCDouble( valueBuffer, &value ); 
  } 
}




QtAtomicData::QtAtomicData( const QtAtomicData& obj )
  : QtScalarData( obj )
{
}

QtAtomicData::~QtAtomicData()
{
}

r_ULong
QtAtomicData::getUnsignedValue() const
{
  r_ULong value=0;

  if( valueType )
    valueType->convertToCULong( valueBuffer, &value );

  return value;  
}



r_Long
QtAtomicData::getSignedValue() const
{
  r_Long value=0;

  if( valueType )
    valueType->convertToCLong( valueBuffer, &value );

  return value;  
}



double
QtAtomicData::getDoubleValue() const
{
  double value=0;

  if( valueType )
    valueType->convertToCDouble( valueBuffer, &value );

  return value;  
}



void
QtAtomicData::printStatus( ostream& stream ) const
{
  stream << "atomic, " << flush;

  QtScalarData::printStatus( stream );
}


// for complex types
QtAtomicData::QtAtomicData(double valRe, double valIm, unsigned short size)
: QtScalarData() {
	double dummyRe = valRe;
	double dummyIm = valIm;

	if(size == 2 * sizeof(float))
		valueType = TypeFactory::mapType("Complex1");
	else
		valueType = TypeFactory::mapType("Complex2");

    valueBuffer = new char[valueType->getSize()];
    valueType->makeFromCDouble(valueBuffer + ((GenericComplexType *)valueType)->getReOffset(), &dummyRe); 
    valueType->makeFromCDouble(valueBuffer + ((GenericComplexType *)valueType)->getImOffset(), &dummyIm); 
}