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 17002 2007-08-27 19:16:51Z pwest $"
00041 };
00042
00043 #include <stdlib.h>
00044
00045 #include "Str.h"
00046 #include "DDS.h"
00047 #include "util.h"
00048 #include "parser.h"
00049
00050 #include "Operators.h"
00051 #include "InternalErr.h"
00052 #include "escaping.h"
00053 #include "debug.h"
00054
00055
00056 using std::cerr;
00057 using std::endl;
00058
00067 Str::Str(const string &n) : BaseType(n, dods_str_c), _buf("")
00068 {}
00069
00070 Str::Str(const Str ©_from) : BaseType(copy_from)
00071 {
00072 _buf = copy_from._buf;
00073 }
00074
00075 BaseType *
00076 Str::ptr_duplicate()
00077 {
00078 return new Str(*this);
00079 }
00080
00081 Str &
00082 Str::operator=(const Str &rhs)
00083 {
00084 if (this == &rhs)
00085 return *this;
00086
00087
00088 dynamic_cast<BaseType &>(*this) = rhs;
00089
00090 _buf = rhs._buf;
00091
00092 return *this;
00093 }
00094
00095 unsigned int
00096 Str::length()
00097 {
00098 return _buf.length();
00099 }
00100
00101 unsigned int
00102 Str::width()
00103 {
00104 return sizeof(string);
00105 }
00106
00107 bool
00108 Str::serialize(const string &dataset, ConstraintEvaluator &eval, DDS &dds,
00109 Marshaller &m, bool ce_eval)
00110 {
00111
00112 DBG(cerr << "Entering (" << this->name() << " [" << this << "])" << endl);
00113
00114 dds.timeout_on();
00115
00116 if (!read_p())
00117 read(dataset);
00118
00119 #if EVAL
00120 if (ce_eval && !eval.eval_selection(dds, dataset))
00121 return true;
00122 #endif
00123
00124 dds.timeout_off();
00125
00126 m.put_str( _buf ) ;
00127
00128 DBG(cerr << "Exiting: buf = " << _buf << endl);
00129
00130 return true;
00131 }
00132
00133
00134
00135 bool
00136 Str::deserialize(UnMarshaller &um, DDS *, bool)
00137 {
00138 um.get_str( _buf ) ;
00139
00140 return false;
00141 }
00142
00152 unsigned int
00153 Str::buf2val(void **val)
00154 {
00155
00156
00157 if (!val)
00158 throw InternalErr(__FILE__, __LINE__,
00159 "No place to store a reference to the data.");
00160
00161
00162
00163 if (!*val)
00164 *val = new string(_buf);
00165 else
00166 *static_cast<string*>(*val) = _buf;
00167
00168 return sizeof(string*);
00169 }
00170
00180 unsigned int
00181 Str::val2buf(void *val, bool)
00182 {
00183
00184
00185
00186
00187 if (!val)
00188 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00189
00190 _buf = *static_cast<string*>(val);
00191
00192 return sizeof(string*);
00193 }
00194
00199 bool
00200 Str::set_value(const string &value)
00201 {
00202 _buf = value;
00203 set_read_p(true);
00204
00205 return true;
00206 }
00207
00210 string
00211 Str::value() const
00212 {
00213 return _buf;
00214 }
00215
00216 void
00217 Str::print_val(FILE *out, string space, bool print_decl_p)
00218 {
00219 if (print_decl_p) {
00220 print_decl(out, space, false);
00221 fprintf(out, " = \"%s\";\n", escattr(_buf).c_str()) ;
00222 }
00223 else
00224 fprintf(out, "\"%s\"", escattr(_buf).c_str()) ;
00225 }
00226
00227 void
00228 Str::print_val(ostream &out, string space, bool print_decl_p)
00229 {
00230 if (print_decl_p) {
00231 print_decl(out, space, false);
00232 out << " = \"" << escattr(_buf) << "\";\n" ;
00233 }
00234 else
00235 out << "\"" << escattr(_buf) << "\"" ;
00236 }
00237
00238 bool
00239 Str::ops(BaseType *b, int op, const string &dataset)
00240 {
00241
00242 if (!read_p() && !read(dataset)) {
00243
00244
00245
00246
00247
00248 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
00249 }
00250
00251
00252 if (!b->read_p() && !b->read(dataset)) {
00253
00254
00255
00256
00257
00258 throw InternalErr(__FILE__, __LINE__, "Argument value was not read!");
00259 }
00260
00261 switch (b->type()) {
00262 case dods_str_c:
00263 return rops<string, string, StrCmp<string, string> >
00264 (_buf, dynamic_cast<Str *>(b)->_buf, op);
00265 case dods_url_c:
00266 return rops<string, string, StrCmp<string, string> >
00267 (_buf, dynamic_cast<Url *>(b)->_buf, op);
00268 default:
00269 return false;
00270 }
00271 }
00272
00281 void
00282 Str::dump(ostream &strm) const
00283 {
00284 strm << DapIndent::LMarg << "Str::dump - ("
00285 << (void *)this << ")" << endl ;
00286 DapIndent::Indent() ;
00287 BaseType::dump(strm) ;
00288 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00289 DapIndent::UnIndent() ;
00290 }
00291