00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "config.h"
00038
00039 static char rcsid[] not_used =
00040 {"$Id: Str.cc 21699 2009-11-05 00:06:01Z jimg $"
00041 };
00042
00043 #include "Byte.h"
00044 #include "Int16.h"
00045 #include "UInt16.h"
00046 #include "Int32.h"
00047 #include "UInt32.h"
00048 #include "Float32.h"
00049 #include "Float64.h"
00050 #include "Str.h"
00051 #include "Url.h"
00052 #include "Array.h"
00053 #include "Structure.h"
00054 #include "Sequence.h"
00055 #include "Grid.h"
00056
00057
00058 #include "DDS.h"
00059 #include "util.h"
00060 #include "parser.h"
00061 #include "Operators.h"
00062 #include "InternalErr.h"
00063 #include "escaping.h"
00064 #include "debug.h"
00065
00066
00067 using std::cerr;
00068 using std::endl;
00069
00070 namespace libdap {
00071
00080 Str::Str(const string &n) : BaseType(n, dods_str_c), _buf("")
00081 {}
00082
00090 Str::Str(const string &n, const string &d)
00091 : BaseType(n, d, dods_str_c), _buf("")
00092 {}
00093
00094 Str::Str(const Str ©_from) : BaseType(copy_from)
00095 {
00096 _buf = copy_from._buf;
00097 }
00098
00099 BaseType *
00100 Str::ptr_duplicate()
00101 {
00102 return new Str(*this);
00103 }
00104
00105 Str &
00106 Str::operator=(const Str &rhs)
00107 {
00108 if (this == &rhs)
00109 return *this;
00110
00111
00112 dynamic_cast<BaseType &>(*this) = rhs;
00113
00114 _buf = rhs._buf;
00115
00116 return *this;
00117 }
00118
00119 unsigned int
00120 Str::length()
00121 {
00122 return _buf.length();
00123 }
00124
00125 unsigned int
00126 Str::width()
00127 {
00128 return sizeof(string);
00129 }
00130
00131 bool
00132 Str::serialize(ConstraintEvaluator &eval, DDS &dds,
00133 Marshaller &m, bool ce_eval)
00134 {
00135
00136 DBG(cerr << "Entering (" << this->name() << " [" << this << "])" << endl);
00137
00138 dds.timeout_on();
00139
00140 if (!read_p())
00141 read();
00142
00143 #if EVAL
00144 if (ce_eval && !eval.eval_selection(dds, dataset()))
00145 return true;
00146 #endif
00147
00148 dds.timeout_off();
00149
00150 m.put_str( _buf ) ;
00151
00152 DBG(cerr << "Exiting: buf = " << _buf << endl);
00153
00154 return true;
00155 }
00156
00157
00158
00159 bool
00160 Str::deserialize(UnMarshaller &um, DDS *, bool)
00161 {
00162 um.get_str( _buf ) ;
00163
00164 return false;
00165 }
00166
00176 unsigned int
00177 Str::buf2val(void **val)
00178 {
00179
00180
00181 if (!val)
00182 throw InternalErr(__FILE__, __LINE__,
00183 "No place to store a reference to the data.");
00184
00185
00186
00187 if (!*val)
00188 *val = new string(_buf);
00189 else
00190 *static_cast<string*>(*val) = _buf;
00191
00192 return sizeof(string*);
00193 }
00194
00204 unsigned int
00205 Str::val2buf(void *val, bool)
00206 {
00207
00208
00209
00210
00211 if (!val)
00212 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00213
00214 _buf = *static_cast<string*>(val);
00215
00216 return sizeof(string*);
00217 }
00218
00223 bool
00224 Str::set_value(const string &value)
00225 {
00226 _buf = value;
00227 set_read_p(true);
00228
00229 return true;
00230 }
00231
00234 string
00235 Str::value() const
00236 {
00237 return _buf;
00238 }
00239
00240 #if FILE_METHODS
00241 void
00242 Str::print_val(FILE *out, string space, bool print_decl_p)
00243 {
00244 if (print_decl_p) {
00245 print_decl(out, space, false);
00246 fprintf(out, " = \"%s\";\n", escattr(_buf).c_str()) ;
00247 }
00248 else
00249 fprintf(out, "\"%s\"", escattr(_buf).c_str()) ;
00250 }
00251 #endif
00252
00253 void
00254 Str::print_val(ostream &out, string space, bool print_decl_p)
00255 {
00256 if (print_decl_p) {
00257 print_decl(out, space, false);
00258 out << " = \"" << escattr(_buf) << "\";\n" ;
00259 }
00260 else
00261 out << "\"" << escattr(_buf) << "\"" ;
00262 }
00263
00264 bool
00265 Str::ops(BaseType *b, int op)
00266 {
00267
00268 if (!read_p() && !read()) {
00269
00270
00271
00272
00273
00274 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
00275 }
00276
00277
00278 if (!b || !(b->read_p() || b->read())) {
00279
00280
00281
00282
00283
00284 throw InternalErr(__FILE__, __LINE__, "Argument value was not read!");
00285 }
00286
00287 switch (b->type()) {
00288 case dods_str_c:
00289 return rops<string, string, StrCmp<string, string> >
00290 (_buf, dynamic_cast<Str *>(b)->_buf, op);
00291 case dods_url_c:
00292 return rops<string, string, StrCmp<string, string> >
00293 (_buf, dynamic_cast<Url *>(b)->_buf, op);
00294 default:
00295 return false;
00296 }
00297 }
00298
00307 void
00308 Str::dump(ostream &strm) const
00309 {
00310 strm << DapIndent::LMarg << "Str::dump - ("
00311 << (void *)this << ")" << endl ;
00312 DapIndent::Indent() ;
00313 BaseType::dump(strm) ;
00314 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00315 DapIndent::UnIndent() ;
00316 }
00317
00318 }
00319