00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011
00012 #include "ncvalues.h"
00013
00014 NcValues::NcValues( void ) : the_type(ncNoType), the_number(0)
00015 {}
00016
00017 NcValues::NcValues(NcType type, long num)
00018 : the_type(type), the_number(num)
00019 {}
00020
00021 NcValues::~NcValues( void )
00022 {}
00023
00024 long NcValues::num( void )
00025 {
00026 return the_number;
00027 }
00028
00029 std::ostream& operator<< (std::ostream& os, const NcValues& vals)
00030 {
00031 return vals.print(os);
00032 }
00033
00034 implement(NcValues,ncbyte)
00035 implement(NcValues,char)
00036 implement(NcValues,short)
00037 implement(NcValues,int)
00038 implement(NcValues,nclong)
00039 implement(NcValues,long)
00040 implement(NcValues,float)
00041 implement(NcValues,double)
00042
00043 Ncbytes_for_one_implement(ncbyte)
00044 Ncbytes_for_one_implement(char)
00045 Ncbytes_for_one_implement(short)
00046 Ncbytes_for_one_implement(int)
00047 Ncbytes_for_one_implement(nclong)
00048 Ncbytes_for_one_implement(long)
00049 Ncbytes_for_one_implement(float)
00050 Ncbytes_for_one_implement(double)
00051
00052 as_ncbyte_implement(short)
00053 as_ncbyte_implement(int)
00054 as_ncbyte_implement(nclong)
00055 as_ncbyte_implement(long)
00056 as_ncbyte_implement(float)
00057 as_ncbyte_implement(double)
00058
00059 inline ncbyte NcValues_char::as_ncbyte( long n ) const
00060 {
00061 return the_values[n];
00062 }
00063
00064 inline ncbyte NcValues_ncbyte::as_ncbyte( long n ) const
00065 {
00066 return the_values[n];
00067 }
00068
00069 as_char_implement(short)
00070 as_char_implement(int)
00071 as_char_implement(nclong)
00072 as_char_implement(long)
00073 as_char_implement(float)
00074 as_char_implement(double)
00075
00076 inline char NcValues_ncbyte::as_char( long n ) const
00077 {
00078 return the_values[n] > CHAR_MAX ? ncBad_char : (char) the_values[n];
00079 }
00080
00081 inline char NcValues_char::as_char( long n ) const
00082 {
00083 return the_values[n];
00084 }
00085
00086 as_short_implement(int)
00087 as_short_implement(nclong)
00088 as_short_implement(long)
00089 as_short_implement(float)
00090 as_short_implement(double)
00091
00092 inline short NcValues_ncbyte::as_short( long n ) const
00093 {
00094 return the_values[n];
00095 }
00096
00097 inline short NcValues_char::as_short( long n ) const
00098 {
00099 return the_values[n];
00100 }
00101
00102 inline short NcValues_short::as_short( long n ) const
00103 {
00104 return the_values[n];
00105 }
00106
00107
00108 as_int_implement(float)
00109 as_int_implement(double)
00110
00111 inline int NcValues_ncbyte::as_int( long n ) const
00112 {
00113 return the_values[n];
00114 }
00115
00116 inline int NcValues_char::as_int( long n ) const
00117 {
00118 return the_values[n];
00119 }
00120
00121 inline int NcValues_short::as_int( long n ) const
00122 {
00123 return the_values[n];
00124 }
00125
00126 inline int NcValues_int::as_int( long n ) const
00127 {
00128 return the_values[n];
00129 }
00130
00131 inline int NcValues_nclong::as_int( long n ) const
00132 {
00133 return the_values[n];
00134 }
00135
00136 inline int NcValues_long::as_int( long n ) const
00137 {
00138 return the_values[n];
00139 }
00140
00141 as_nclong_implement(float)
00142 as_nclong_implement(double)
00143
00144 inline nclong NcValues_ncbyte::as_nclong( long n ) const
00145 {
00146 return the_values[n];
00147 }
00148
00149 inline nclong NcValues_char::as_nclong( long n ) const
00150 {
00151 return the_values[n];
00152 }
00153
00154 inline nclong NcValues_short::as_nclong( long n ) const
00155 {
00156 return the_values[n];
00157 }
00158
00159 inline nclong NcValues_int::as_nclong( long n ) const
00160 {
00161 return the_values[n];
00162 }
00163
00164 inline nclong NcValues_nclong::as_nclong( long n ) const
00165 {
00166 return the_values[n];
00167 }
00168
00169 inline nclong NcValues_long::as_nclong( long n ) const
00170 {
00171 return the_values[n];
00172 }
00173
00174 as_long_implement(float)
00175 as_long_implement(double)
00176
00177 inline long NcValues_ncbyte::as_long( long n ) const
00178 {
00179 return the_values[n];
00180 }
00181
00182 inline long NcValues_char::as_long( long n ) const
00183 {
00184 return the_values[n];
00185 }
00186
00187 inline long NcValues_short::as_long( long n ) const
00188 {
00189 return the_values[n];
00190 }
00191
00192 inline long NcValues_int::as_long( long n ) const
00193 {
00194 return the_values[n];
00195 }
00196
00197 inline long NcValues_nclong::as_long( long n ) const
00198 {
00199 return the_values[n];
00200 }
00201
00202 inline long NcValues_long::as_long( long n ) const
00203 {
00204 return the_values[n];
00205 }
00206
00207 as_float_implement(ncbyte)
00208 as_float_implement(char)
00209 as_float_implement(short)
00210 as_float_implement(int)
00211 as_float_implement(nclong)
00212 as_float_implement(long)
00213 as_float_implement(float)
00214 as_float_implement(double)
00215
00216 as_double_implement(ncbyte)
00217 as_double_implement(char)
00218 as_double_implement(short)
00219 as_double_implement(int)
00220 as_double_implement(nclong)
00221 as_double_implement(long)
00222 as_double_implement(float)
00223 as_double_implement(double)
00224
00225 as_string_implement(short)
00226 as_string_implement(int)
00227 as_string_implement(nclong)
00228 as_string_implement(long)
00229 as_string_implement(float)
00230 as_string_implement(double)
00231
00232 inline char* NcValues_ncbyte::as_string( long n ) const
00233 {
00234 char* s = new char[the_number + 1];
00235 s[the_number] = '\0';
00236 strncpy(s, (const char*)the_values + n, (int)the_number);
00237 return s;
00238 }
00239
00240 inline char* NcValues_char::as_string( long n ) const
00241 {
00242 char* s = new char[the_number + 1];
00243 s[the_number] = '\0';
00244 strncpy(s, (const char*)the_values + n, (int)the_number);
00245 return s;
00246 }
00247
00248 std::ostream& NcValues_short::print(std::ostream& os) const
00249 {
00250 for(int i = 0; i < the_number - 1; i++)
00251 os << the_values[i] << ", ";
00252 if (the_number > 0)
00253 os << the_values[the_number-1] ;
00254 return os;
00255 }
00256
00257 std::ostream& NcValues_int::print(std::ostream& os) const
00258 {
00259 for(int i = 0; i < the_number - 1; i++)
00260 os << the_values[i] << ", ";
00261 if (the_number > 0)
00262 os << the_values[the_number-1] ;
00263 return os;
00264 }
00265
00266 std::ostream& NcValues_nclong::print(std::ostream& os) const
00267 {
00268 for(int i = 0; i < the_number - 1; i++)
00269 os << the_values[i] << ", ";
00270 if (the_number > 0)
00271 os << the_values[the_number-1] ;
00272 return os;
00273 }
00274
00275 std::ostream& NcValues_long::print(std::ostream& os) const
00276 {
00277 for(int i = 0; i < the_number - 1; i++)
00278 os << the_values[i] << ", ";
00279 if (the_number > 0)
00280 os << the_values[the_number-1] ;
00281 return os;
00282 }
00283
00284 std::ostream& NcValues_ncbyte::print(std::ostream& os) const
00285 {
00286 for(int i = 0; i < the_number - 1; i++)
00287 os << the_values[i] << ", ";
00288 if (the_number > 0)
00289 os << the_values[the_number-1] ;
00290 return os;
00291 }
00292
00293 std::ostream& NcValues_char::print(std::ostream& os) const
00294 {
00295 os << '"';
00296 long len = the_number;
00297 while (the_values[--len] == '\0')
00298 ;
00299 for(int i = 0; i <= len; i++)
00300 os << the_values[i] ;
00301 os << '"';
00302
00303 return os;
00304 }
00305
00306 std::ostream& NcValues_float::print(std::ostream& os) const
00307 {
00308 std::streamsize save=os.precision();
00309 os.precision(7);
00310 for(int i = 0; i < the_number - 1; i++)
00311 os << the_values[i] << ", ";
00312 if (the_number > 0)
00313 os << the_values[the_number-1] ;
00314 os.precision(save);
00315 return os;
00316 }
00317
00318 std::ostream& NcValues_double::print(std::ostream& os) const
00319 {
00320 std::streamsize save=os.precision();
00321 os.precision(15);
00322 for(int i = 0; i < the_number - 1; i++)
00323 os << the_values[i] << ", ";
00324 if (the_number > 0)
00325 os << the_values[the_number-1];
00326 os.precision(save);
00327 return os;
00328 }