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
|
/*********************************************************************
* Copyright 1992, University Corporation for Atmospheric Research
* See netcdf/README file for copying and redistribution conditions.
*
* Purpose: implementation of classes of typed arrays for netCDF
*
* $Header: /hdf/src/master/dist/mfhdf/c++/ncvalues.cc,v 1.2 1993/04/30 20:29:40 koziol Exp $
*********************************************************************/
#include <iostream.h> // for debugging
#include "ncvalues.hh"
NcValues::NcValues( void ) : the_number(0), the_type(ncNoType)
{}
NcValues::NcValues(NcType type, long num)
: the_number(num), the_type(type)
{}
NcValues::~NcValues( void )
{}
long NcValues::num( void )
{
return the_number;
}
ostream& operator<< (ostream& os, const NcValues& vals)
{
return vals.print(os);
}
implement(NcValues,ncbyte)
implement(NcValues,char)
implement(NcValues,short)
implement(NcValues,long)
implement(NcValues,int)
implement(NcValues,float)
implement(NcValues,double)
Ncbytes_for_one_implement(ncbyte)
Ncbytes_for_one_implement(char)
Ncbytes_for_one_implement(short)
Ncbytes_for_one_implement(long)
Ncbytes_for_one_implement(float)
Ncbytes_for_one_implement(double)
int NcValues_int::bytes_for_one( void ) const
{
return nctypelen( NC_LONG ); // *** treat "int" as "long" for now
}
as_ncbyte_implement(short)
as_ncbyte_implement(int)
as_ncbyte_implement(long)
as_ncbyte_implement(float)
as_ncbyte_implement(double)
inline ncbyte NcValues_char::as_ncbyte( int n ) const
{
return the_values[n] < 0 ? ncBad_byte : (ncbyte) the_values[n];
}
inline ncbyte NcValues_ncbyte::as_ncbyte( int n ) const
{
return the_values[n];
}
as_char_implement(short)
as_char_implement(int)
as_char_implement(long)
as_char_implement(float)
as_char_implement(double)
inline char NcValues_ncbyte::as_char( int n ) const
{
return the_values[n] > CHAR_MAX ? ncBad_char : (char) the_values[n];
}
inline char NcValues_char::as_char( int n ) const
{
return the_values[n];
}
as_short_implement(int)
as_short_implement(long)
as_short_implement(float)
as_short_implement(double)
inline short NcValues_ncbyte::as_short( int n ) const
{
return the_values[n];
}
inline short NcValues_char::as_short( int n ) const
{
return the_values[n];
}
inline short NcValues_short::as_short( int n ) const
{
return the_values[n];
}
as_long_implement(float)
as_long_implement(double)
inline long NcValues_ncbyte::as_long( int n ) const
{
return the_values[n];
}
inline long NcValues_char::as_long( int n ) const
{
return the_values[n];
}
inline long NcValues_short::as_long( int n ) const
{
return the_values[n];
}
inline long NcValues_int::as_long( int n ) const
{
return the_values[n];
}
inline long NcValues_long::as_long( int n ) const
{
return the_values[n];
}
as_float_implement(ncbyte)
as_float_implement(char)
as_float_implement(short)
as_float_implement(int)
as_float_implement(long)
as_float_implement(float)
as_float_implement(double)
as_double_implement(ncbyte)
as_double_implement(char)
as_double_implement(short)
as_double_implement(int)
as_double_implement(long)
as_double_implement(float)
as_double_implement(double)
as_string_implement(short)
as_string_implement(int)
as_string_implement(long)
as_string_implement(float)
as_string_implement(double)
inline char* NcValues_ncbyte::as_string( int n ) const
{
return strdup((char*)the_values + n);
}
inline char* NcValues_char::as_string( int n ) const
{
return strdup(the_values + n);
}
ostream& NcValues_short::print(ostream& os) const
{
for(int i = 0; i < the_number - 1; i++)
os << the_values[i] << ", ";
if (the_number > 0)
os << the_values[the_number-1] ;
return os;
}
ostream& NcValues_long::print(ostream& os) const
{
for(int i = 0; i < the_number - 1; i++)
os << the_values[i] << ", ";
if (the_number > 0)
os << the_values[the_number-1] ;
return os;
}
ostream& NcValues_int::print(ostream& os) const
{
for(int i = 0; i < the_number - 1; i++)
os << the_values[i] << ", ";
if (the_number > 0)
os << the_values[the_number-1] ;
return os;
}
ostream& NcValues_ncbyte::print(ostream& os) const
{
for(int i = 0; i < the_number - 1; i++)
os << the_values[i] << ", ";
if (the_number > 0)
os << the_values[the_number-1] ;
return os;
}
ostream& NcValues_char::print(ostream& os) const
{
os << '"' << the_values <<'"';
return os;
}
ostream& NcValues_float::print(ostream& os) const
{
long save=os.flags();
os.precision(7);
for(int i = 0; i < the_number - 1; i++)
os << the_values[i] << ", ";
if (the_number > 0)
os << the_values[the_number-1] ;
os.flags(save);
return os;
}
ostream& NcValues_double::print(ostream& os) const
{
long save=os.flags();
os.precision(15);
for(int i = 0; i < the_number - 1; i++)
os << the_values[i] << ", ";
if (the_number > 0)
os << the_values[the_number-1];
os.flags(save);
return os;
}
|