00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _SECSTWOMSG_INTERNAL_HPP
00021 #define _SECSTWOMSG_INTERNAL_HPP
00022 #include <errno.h>
00023 #include <iostream>
00024 #include <iconv.h>
00025 #include "secstwomsg.h"
00026
00027 namespace freesecs
00028 {
00029 namespace secstwo
00030 {
00034 template<data_type_t> struct type_selector
00035 {
00036 typedef void * data_type;
00037 };
00041 template<> struct type_selector<e_list_t>
00042 {
00043 typedef pdata_item_t data_type;
00044 typedef int print_type;
00045 typedef std::vector<data_type> container_type;
00046 };
00050 template<> struct type_selector<e_binary_t>
00051 {
00052 typedef uint8_t data_type;
00053 typedef uint16_t print_type;
00054 typedef std::vector<data_type> container_type;
00055 };
00059 template<> struct type_selector<e_boolean_t>
00060 {
00061 typedef bool data_type;
00062 typedef bool print_type;
00063 typedef std::vector<uint8_t> container_type;
00064 };
00068 template<> struct type_selector<e_ascii_t>
00069 {
00070 typedef char data_type;
00071 typedef data_type print_type;
00072 typedef std::string container_type;
00073 };
00077 template<> struct type_selector<e_jis8_t>
00078 {
00079 typedef char data_type;
00080 typedef data_type print_type;
00081 typedef std::string container_type;
00082 };
00086 template<> struct type_selector<e_wchar_t>
00087 {
00088 typedef char data_type;
00089 typedef data_type print_type;
00090 typedef std::string container_type;
00091 };
00095 template<> struct type_selector<e_int64_t>
00096 {
00097 typedef int64_t data_type;
00098 typedef data_type print_type;
00099 typedef std::vector<data_type> container_type;
00100 };
00104 template<> struct type_selector<e_int8_t>
00105 {
00106 typedef int8_t data_type;
00107 typedef int16_t print_type;
00108 typedef std::vector<data_type> container_type;
00109 };
00113 template<> struct type_selector<e_int16_t>
00114 {
00115 typedef int16_t data_type;
00116 typedef data_type print_type;
00117 typedef std::vector<data_type> container_type;
00118 };
00122 template<> struct type_selector<e_int32_t>
00123 {
00124 typedef int32_t data_type;
00125 typedef data_type print_type;
00126 typedef std::vector<data_type> container_type;
00127 };
00131 template<> struct type_selector<e_double_t>
00132 {
00133 typedef double data_type;
00134 typedef data_type print_type;
00135 typedef std::vector<data_type> container_type;
00136 };
00140 template<> struct type_selector<e_float_t>
00141 {
00142 typedef float data_type;
00143 typedef data_type print_type;
00144 typedef std::vector<data_type> container_type;
00145 };
00149 template<> struct type_selector<e_uint64_t>
00150 {
00151 typedef uint64_t data_type;
00152 typedef data_type print_type;
00153 typedef std::vector<data_type> container_type;
00154 };
00158 template<> struct type_selector<e_uint8_t>
00159 {
00160 typedef uint8_t data_type;
00161 typedef uint16_t print_type;
00162 typedef std::vector<data_type> container_type;
00163 };
00167 template<> struct type_selector<e_uint16_t>
00168 {
00169 typedef uint16_t data_type;
00170 typedef data_type print_type;
00171 typedef std::vector<data_type> container_type;
00172 };
00176 template<> struct type_selector<e_uint32_t>
00177 {
00178 typedef uint32_t data_type;
00179 typedef data_type print_type;
00180 typedef std::vector<data_type> container_type;
00181 };
00182
00189 template<data_type_t _type>
00190 class msg_item_impl_t : public data_item_t
00191 {
00192 public:
00193 typedef typename type_selector<_type>::data_type data_t;
00194 typedef typename type_selector<_type>::print_type print_t;
00195 typedef typename type_selector<_type>::container_type container_t;
00196 public:
00197 msg_item_impl_t(const char* name)
00198 :data_item_t(name),_access_index(0)
00199 {}
00200 msg_item_impl_t(const char *name,
00201 const container_t &data)
00202 :data_item_t(name),_access_index(0),_data(data)
00203 {}
00204 msg_item_impl_t(const msg_item_impl_t &oth)
00205 :data_item_t(oth.name()),_access_index(0),_data(oth._data)
00206 {}
00207 virtual data_item_t& operator[](uint32_t ix)
00208 {
00209 _access_index = ix;
00210 return *this;
00211 }
00212 virtual operator bool () const
00213 {
00214 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00215 _access_index = 0;
00216
00217 return _data[ix];
00218 }
00219 virtual operator int8_t () const
00220 {
00221 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00222 _access_index = 0;
00223
00224 return _data[ix];
00225 }
00226 virtual operator uint8_t () const
00227 {
00228 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00229 _access_index = 0;
00230
00231 return _data[ix];
00232 }
00233 virtual operator int16_t () const
00234 {
00235 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00236 _access_index = 0;
00237
00238 return _data[ix];
00239 }
00240 virtual operator uint16_t () const
00241 {
00242 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00243 _access_index = 0;
00244
00245 return _data[ix];
00246 }
00247 virtual operator int32_t () const
00248 {
00249 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00250 _access_index = 0;
00251
00252 return _data[ix];
00253 }
00254 virtual operator uint32_t () const
00255 {
00256 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00257 _access_index = 0;
00258
00259 return _data[ix];
00260 }
00261 virtual operator uint64_t () const
00262 {
00263 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00264 _access_index = 0;
00265
00266 return _data[ix];
00267 }
00268 virtual operator int64_t () const
00269 {
00270 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00271 _access_index = 0;
00272
00273 return (int64_t)_data[ix];
00274 }
00275 virtual operator float () const
00276 {
00277 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00278 _access_index = 0;
00279
00280 return _data[ix];
00281 }
00282 virtual operator double () const
00283 {
00284 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00285 _access_index = 0;
00286
00287 return _data[ix];
00288 }
00289 virtual data_item_t& operator = (const bool &data)
00290 {
00291 _data.clear();
00292 _data.push_back(data);
00293 return *this;
00294 }
00295 virtual data_item_t& operator = (const uint8_t &data)
00296 {
00297 _data.clear();
00298 _data.push_back(data);
00299 return *this;
00300 }
00301 virtual data_item_t& operator = (const int8_t &data)
00302 {
00303 _data.clear();
00304 _data.push_back(data);
00305 return *this;
00306 }
00307 virtual data_item_t& operator = (const uint16_t &data)
00308 {
00309 _data.clear();
00310 _data.push_back(data);
00311 return *this;
00312 }
00313 virtual data_item_t& operator = (const int16_t &data)
00314 {
00315 _data.clear();
00316 _data.push_back(data);
00317 return *this;
00318 }
00319 virtual data_item_t& operator = (const uint32_t &data)
00320 {
00321 _data.clear();
00322 _data.push_back(data);
00323 return *this;
00324 }
00325 virtual data_item_t& operator = (const int32_t &data)
00326 {
00327 _data.clear();
00328 _data.push_back(data);
00329 return *this;
00330 }
00331 virtual data_item_t& operator = (const uint64_t &data)
00332 {
00333 _data.clear();
00334 _data.push_back(data);
00335 return *this;
00336 }
00337 virtual data_item_t& operator = (const int64_t &data)
00338 {
00339 _data.clear();
00340 _data.push_back(data);
00341 return *this;
00342 }
00343 virtual data_item_t& operator = (const double &data)
00344 {
00345 _data.clear();
00346 _data.push_back(data);
00347 return *this;
00348 }
00349 virtual data_item_t& operator = (const float &data)
00350 {
00351 _data.clear();
00352 _data.push_back(data);
00353 return *this;
00354 }
00355 virtual data_item_t& operator += (const bool &data)
00356 {
00357 _data.push_back(data);
00358 return *this;
00359 }
00360 virtual data_item_t& operator += (const uint8_t &data)
00361 {
00362 _data.push_back(data);
00363 return *this;
00364 }
00365 virtual data_item_t& operator += (const int8_t &data)
00366 {
00367 _data.push_back(data);
00368 return *this;
00369 }
00370 virtual data_item_t& operator += (const uint16_t &data)
00371 {
00372 _data.push_back(data);
00373 return *this;
00374 }
00375 virtual data_item_t& operator += (const int16_t &data)
00376 {
00377 _data.push_back(data);
00378 return *this;
00379 }
00380 virtual data_item_t& operator += (const uint32_t &data)
00381 {
00382 _data.push_back(data);
00383 return *this;
00384 }
00385 virtual data_item_t& operator += (const int32_t &data)
00386 {
00387 _data.push_back(data);
00388 return *this;
00389 }
00390 virtual data_item_t& operator += (const uint64_t &data)
00391 {
00392 _data.push_back(data);
00393 return *this;
00394 }
00395 virtual data_item_t& operator += (const int64_t &data)
00396 {
00397 _data.push_back(data);
00398 return *this;
00399 }
00400 virtual data_item_t& operator += (const double &data)
00401 {
00402 _data.push_back(data);
00403 return *this;
00404 }
00405 virtual data_item_t& operator += (const float &data)
00406 {
00407 _data.push_back(data);
00408 return *this;
00409 }
00410 data_t get_curr_item()const
00411 {
00412 uint32_t ix = _access_index < _data.size() ? _access_index : 0;
00413 _access_index = 0;
00414 return _data.at(ix);
00415 }
00416 virtual bool operator == (const bool &v)const
00417 {
00418 return v == get_curr_item();
00419 }
00420 virtual bool operator == (const int8_t &v)const
00421 {
00422 return v == get_curr_item();
00423 }
00424 virtual bool operator == (const uint8_t &v)const
00425 {
00426 return v == get_curr_item();
00427 }
00428 virtual bool operator == (const int16_t &v)const
00429 {
00430 return v == get_curr_item();
00431 }
00432 virtual bool operator == (const uint16_t &v)const
00433 {
00434 return v == get_curr_item();
00435 }
00436 virtual bool operator == (const int32_t &v)const
00437 {
00438 return v == get_curr_item();
00439 }
00440 virtual bool operator == (const uint32_t &v)const
00441 {
00442 return v == get_curr_item();
00443 }
00444 virtual bool operator == (const int64_t &v)const
00445 {
00446 return v == get_curr_item();
00447 }
00448 virtual bool operator == (const uint64_t &v)const
00449 {
00450 return v == get_curr_item();
00451 }
00452 virtual bool operator == (const float &v)const
00453 {
00454 return v == get_curr_item();
00455 }
00456 virtual bool operator == (const double &v)const
00457 {
00458 return v == get_curr_item();
00459 }
00460 virtual bool match(const data_item_t& other, match_t match=ALL)const
00461 {
00462 if(other.type() != _type)
00463 {
00464 return false;
00465 }
00466 else if(STRUCT == match)
00467 {
00468 return true;
00469 }
00470 else
00471 {
00472 const msg_item_impl_t<_type> *pimpl = static_cast<const msg_item_impl_t<_type>*>(&other);
00473 if(_data != pimpl->_data)
00474 {
00475 return false;
00476 }
00477 }
00478
00479 return true;
00480 }
00481 virtual data_type_t type()const
00482 {
00483 return _type;
00484 }
00485
00486 virtual size_t size()const
00487 {
00488 return _data.size();
00489 }
00490
00491 virtual void print(std::ostream& os, const char *prefix = NULL)const
00492 {
00493 static char type2str[][7] =
00494 {"LIST","","","","","","","","BINARY","BOOL","","","","","",
00495 "", "ASCII","JIS-8","WCHAR","","","","","","I64","I8","I16","","I32","",
00496 "","","DOUBLE","","","","FLOAT","","","","UI64","UI8","UI16","","UI32"
00497 };
00498
00499 if(prefix)
00500 {
00501 os << prefix;
00502 }
00503
00504 os << "<" << type2str[type()] <<" \'" << name() <<"\' " << "[" << _data.size() << "] ";
00505
00506 typename container_t::const_iterator it;
00507 for(it = _data.begin(); it != _data.end(); ++it)
00508 {
00509 os << (print_t)*it;
00510 }
00511 os << ">" << std::endl;
00512 }
00513
00514 const container_t& container()const
00515 {
00516 return _data;
00517 }
00518
00519 virtual size_t raw_size() const
00520 {
00521 return size()*sizeof(data_t);
00522 }
00523
00524 virtual int copy_data(const data_item_t &o)
00525 {
00526 if(_type != o.type()) return -1;
00527
00528 const msg_item_impl_t<_type> *pimpl = static_cast<const msg_item_impl_t<_type>*>(&o);
00529
00530 _data = pimpl->_data;
00531
00532 return 0;
00533 }
00534 public:
00535 virtual pdata_item_t clone() const
00536 {
00537 return (data_item_t*)new msg_item_impl_t<_type>(*this);
00538 }
00539 virtual void clear_data()
00540 {
00541 _data.clear();
00542 }
00543 protected:
00544 mutable uint32_t _access_index;
00545
00546 protected:
00547 container_t _data;
00548
00549 private:
00550 friend class binary_deserializer_t;
00551 friend class xml_deserializer_t;
00552
00553 };
00559 class list_item_t : public data_item_t
00560 {
00561 public:
00562 typedef type_selector<e_list_t>::data_type data_t;
00563 typedef type_selector<e_list_t>::print_type print_t;
00564 typedef type_selector<e_list_t>::container_type container_t;
00565 public:
00566 list_item_t(const char *name)
00567 :data_item_t(name)
00568 {};
00569
00570 virtual data_type_t type()const {return e_list_t;}
00571 virtual data_item_t& operator[](uint32_t ix)
00572 {
00573 if(ix >= _data.size())
00574 {
00575 return *this;
00576 }
00577
00578 return *(_data[ix]);
00579 }
00580 virtual data_item_t& operator[](const char *key)
00581 {
00582 container_t::iterator it =
00583 std::find_if(_data.begin(), _data.end(), std::bind2nd(match_name(), key));
00584
00585 if(it != _data.end())
00586 {
00587 return (*it)->operator[](key);
00588 }
00589 return *this;
00590 }
00591 data_item_t&
00592 operator += (const pdata_item_t& pit)
00593 {
00594 return *this;
00595 }
00602 virtual uint32_t size()const
00603 {
00604 return _data.size();
00605 }
00606
00607 virtual bool variable()const{return false;}
00608
00609 virtual void print(std::ostream& os, const char *prefix)const
00610 {
00611 std::string prefix_string = "";
00612
00613 if(prefix)
00614 {
00615 prefix_string += prefix;
00616 }
00617
00618 os << prefix_string
00619 << "<L '"
00620 << name() << "' ["
00621 << _data.size()
00622 << "]" << std::endl;
00623
00624 prefix_string += "\t";
00625
00626 for(container_t::const_iterator it = _data.begin(); it != _data.end(); ++it)
00627 {
00628 (*it)->print(os, prefix_string.c_str());
00629 }
00630
00631 prefix_string.erase(prefix_string.end() -1);
00632
00633 os << prefix_string << ">" << std::endl;
00634 }
00635
00636 virtual size_t raw_size() const
00637 {
00638 size_t total = 0;
00639 for(container_t::const_iterator it = _data.begin(); it != _data.end(); ++it)
00640 {
00641 total += (*it)->raw_size();
00642 }
00643
00644 return total;
00645 }
00646
00647 virtual bool match(const data_item_t& other, match_t kind=ALL)const
00648 {
00649 if(other.type() != this->type())
00650 {
00651 return false;
00652 }
00653
00654 const list_item_t *pother = static_cast<const list_item_t*>(&other);
00655
00656 if(false == variable())
00657 {
00658 if(_data.size() != pother->_data.size())
00659 {
00660 return false;
00661 }
00662 }
00663
00664 container_t::const_iterator this_it, other_it;
00665 for( this_it = _data.begin(), other_it = pother->_data.begin();
00666 this_it < _data.end() && other_it < pother->_data.end();
00667 ++this_it, ++other_it )
00668 {
00669 if(false == (*this_it)->match(*other_it->get(), kind))
00670 {
00671 return false;
00672 }
00673 }
00674
00675 return true;
00676 }
00677 virtual pdata_item_t clone() const
00678 {
00679 list_item_t *plist = new list_item_t(name());
00680 container_t::const_iterator it;
00681 for(it = _data.begin(); it < _data.end(); ++it)
00682 {
00683 plist->_data.push_back((*it)->clone());
00684 }
00685 return plist;
00686 }
00687 virtual void clear_data()
00688 {
00689 container_t::iterator it;
00690 for(it = _data.begin(); it < _data.end(); ++it)
00691 {
00692 (*it)->clear_data();
00693 }
00694 }
00695 virtual int copy_data(const data_item_t &o)
00696 {
00697 int r, ret = 0;
00698 if(e_list_t != o.type()) return -1;
00699
00700 const list_item_t *pother = static_cast<const list_item_t*>(&o);
00701
00702 container_t::iterator this_it;
00703 container_t::const_iterator other_it;
00704 for( this_it = _data.begin(), other_it = pother->_data.begin();
00705 this_it < _data.end() && other_it < pother->_data.end();
00706 ++this_it, ++other_it )
00707 {
00708 if((r = (*this_it)->copy_data(**other_it)))
00709 {
00710 ret = r;
00711 }
00712 }
00713 return ret;
00714 }
00715 protected:
00716 struct match_name
00717 :public std::binary_function<data_t, const char*, bool>
00718 {
00719 bool operator()(data_t &item, const char *name)const
00720 {
00721 data_item_t &data_ref = item->operator[](name);
00722
00723 return 0 == strcmp(data_ref.name(), name);
00724 }
00725 };
00726 protected:
00727 container_t _data;
00728 friend class binary_deserializer_t;
00729 friend class xml_deserializer_t;
00730 friend class binary_serializer_t;
00731 friend class xml_serializer_t;
00732 };
00738 class var_list_item_t : public list_item_t
00739 {
00740 public:
00741 var_list_item_t(const char *name)
00742 :list_item_t(name){}
00743
00744 virtual bool variable()const{return true;}
00745
00746 virtual pdata_item_t clone() const
00747 {
00748 var_list_item_t *plist = new var_list_item_t(name());
00749 plist->_template = _template->clone();
00750
00751 container_t::const_iterator it;
00752 for(it = _data.begin(); it < _data.end(); ++it)
00753 {
00754 plist->_data.push_back((*it)->clone());
00755 }
00756
00757 return plist;
00758 }
00759 data_item_t&
00760 operator += (const pdata_item_t& pit)
00761 {
00762 if( pit.get()
00763 && _template.get()
00764 && true == _template->match(*pit.get(), STRUCT)
00765 )
00766 {
00767 _data.push_back(pit->clone());
00768 }
00769 return *this;
00770 }
00771 virtual bool match(const data_item_t& other, match_t kind=ALL)const
00772 {
00773 const var_list_item_t *pother = static_cast<const var_list_item_t*>(&other);
00774 switch(kind)
00775 {
00776 case STRUCT:
00777 return _template->match(*pother->_template.get(),STRUCT);
00778 break;
00779 case ALL:
00780 if(false == _template->match(*pother->_template.get(),STRUCT)) return false;
00781 break;
00782 case DATA:
00783 case NON_EMPTY_DATA:
00784 default:
00785 break;
00786 }
00787 return list_item_t::match(other, kind);
00788 }
00789 virtual void clear_data()
00790 {
00791 _data.clear();
00792 }
00793 virtual int copy_data(const data_item_t &o)
00794 {
00795 int r, ret = 0;
00796 if(e_list_t != o.type()) return -1;
00797
00798 const list_item_t *pother = static_cast<const list_item_t*>(&o);
00799
00800 if(!pother->variable())
00801 {
00802 return -1;
00803 }
00804 const var_list_item_t *pvar_other = static_cast<const var_list_item_t*>(&o);
00805
00806 if(!_template->match(*pvar_other->_template))
00807 {
00808 return -1;
00809 }
00810
00811 _data = pvar_other->_data;
00812
00813 return 0;
00814 }
00815
00816 virtual data_item_t& operator[](uint32_t ix)
00817 {
00818 if(VAR_ARRAY_ELEMENT == ix)
00819 {
00820 return *_template;
00821 }
00822
00823 return list_item_t::operator[](ix);
00824 }
00825 private:
00832 pdata_item_t _template;
00833 friend class binary_deserializer_t;
00834 friend class xml_deserializer_t;
00835 friend class binary_serializer_t;
00836 friend class xml_serializer_t;
00837 };
00838
00847 template<data_type_t _type>
00848 class string_data_item_t : public data_item_t
00849 {
00850 public:
00851 typedef typename type_selector<_type>::data_type data_t;
00852 typedef typename type_selector<_type>::print_type print_t;
00853 typedef typename type_selector<_type>::container_type container_t;
00854 public:
00855 container_t _data;
00856 public:
00857 string_data_item_t(const char *name)
00858 :data_item_t(name)
00859 {}
00860 string_data_item_t(const char *name, uint8_t *data)
00861 :data_item_t(name)
00862 {
00863 _data = container_t((data_t*)data);
00864 }
00865 string_data_item_t(const char *name, uint8_t *data, size_t data_len)
00866 :data_item_t(name)
00867 {
00868 _data = container_t((data_t*)data,
00869 data_len/sizeof(data_t));
00870 }
00871
00872 string_data_item_t(const char *name, const wchar_t *data)
00873 :data_item_t(name)
00874 {
00875 size_t in_strlen = wcslen(data)*sizeof(wchar_t);
00876 size_t out_strlen = in_strlen;
00877 size_t converted;
00878
00879 iconv_t icd = iconv_open("UTF-8", "WCHAR_T");
00880
00881 if(-1 == (int)icd)
00882 {
00883 throw;
00884 }
00885
00886 char *out_str = new char[out_strlen];
00887 char *out_ptr = out_str;
00888 memset(out_str, 0, out_strlen);
00889
00890 while(out_strlen && in_strlen)
00891 {
00892 converted = iconv(icd, (char**)&data, &in_strlen, &out_ptr, &out_strlen);
00893
00894 if(-1 == (int)converted)
00895 {
00896 delete out_str;
00897 throw;
00898 }
00899 }
00900 iconv_close(icd);
00901 _data = container_t((data_t*)out_str);
00902 delete out_str;
00903 }
00904 virtual data_type_t type()const
00905 {
00906 return _type;
00907 }
00908 virtual operator std::string () const
00909 {
00910 return _data;
00911 }
00912 virtual data_item_t& operator = (const char *data)
00913 {
00914 _data.clear();
00915 _data = data;
00916 return *this;
00917 }
00918 virtual data_item_t& operator = (const std::string &data)
00919 {
00920 _data.clear();
00921 _data = data;
00922 return *this;
00923 }
00924 virtual data_item_t& operator += (const char *data)
00925 {
00926 _data = _data + container_t(data);
00927 return *this;
00928 }
00929 virtual data_item_t& operator += (const std::string &data)
00930 {
00931 _data = _data + data;
00932 return *this;
00933 }
00934 virtual bool operator == (const std::string &o)const
00935 {
00936 std::cout << "string comparison: " << this->_data.compare(o) << std::endl;
00937 return 0 == this->_data.compare(o) ? true : false;
00938 }
00939 virtual bool match(const data_item_t& other, match_t match=ALL)const
00940 {
00941 if(other.type() != _type)
00942 {
00943 return false;
00944 }
00945 else if(STRUCT == match)
00946 {
00947 return true;
00948 }
00949 else
00950 {
00951 const string_data_item_t<_type> *pimpl = static_cast<const string_data_item_t<_type>*>(&other);
00952 if(0 != strcmp(_data.c_str(), pimpl->_data.c_str()))
00953 {
00954 return false;
00955 }
00956 }
00957
00958 return true;
00959 }
00960
00961 virtual pdata_item_t clone() const
00962 {
00963 string_data_item_t<_type> *pcloned = new string_data_item_t<_type>(name());
00964 pcloned->_data = _data;
00965 return pcloned;
00966 }
00967 virtual void clear_data()
00968 {
00969 _data.clear();
00970 }
00971 virtual int copy_data(const data_item_t &o)
00972 {
00973 if(_type != o.type()) return -1;
00974
00975 const string_data_item_t<_type> *pimpl = static_cast<const string_data_item_t<_type>*>(&o);
00976
00977 _data = pimpl->_data;
00978
00979 return 0;
00980 }
00981 virtual size_t size() const
00982 {
00983 return _data.size();
00984 }
00985 virtual size_t raw_size() const
00986 {
00987 return _data.size()*sizeof(data_t);
00988 }
00989 virtual void print(std::ostream& os, const char *prefix = NULL)const
00990 {
00991 static char type2str[][7] =
00992 {"LIST","","","","","","","","BINARY","BOOL","","","","","",
00993 "", "ASCII","JIS-8","WCHAR","","","","","","I64","I8","I16","","I32","",
00994 "","","DOUBLE","","","","FLOAT","","","","UI64","UI8","UI16","","UI32"
00995 };
00996
00997 if(prefix)
00998 {
00999 os << prefix;
01000 }
01001
01002 os << "<" << type2str[type()] <<" \'" << name() <<"\' " << "[" << _data.size() << "] ";
01003
01004 typename container_t::const_iterator it;
01005 for(it = _data.begin(); it != _data.end(); ++it)
01006 {
01007 os << (print_t)*it;
01008 }
01009 os << ">" << std::endl;
01010 }
01011 };
01012
01016 typedef msg_item_impl_t<e_int8_t> int8_item_t ;
01020 typedef msg_item_impl_t<e_int16_t> int16_item_t ;
01024 typedef msg_item_impl_t<e_int32_t> int32_item_t ;
01028 typedef msg_item_impl_t<e_int64_t> int64_item_t ;
01032 typedef msg_item_impl_t<e_binary_t> binary_item_t ;
01036 typedef msg_item_impl_t<e_uint8_t> uint8_item_t ;
01040 typedef msg_item_impl_t<e_uint16_t> uint16_item_t ;
01044 typedef msg_item_impl_t<e_uint32_t> uint32_item_t ;
01048 typedef msg_item_impl_t<e_uint64_t> uint64_item_t ;
01052 typedef msg_item_impl_t<e_float_t> float_item_t ;
01056 typedef msg_item_impl_t<e_double_t> double_item_t ;
01060 typedef msg_item_impl_t<e_boolean_t> bool_item_t ;
01064 typedef string_data_item_t<e_ascii_t> ascii_item_t ;
01068 typedef string_data_item_t<e_jis8_t> jis8_item_t ;
01072 typedef string_data_item_t<e_wchar_t> wchar_item_t ;
01073
01078 class msg_impl_t : public msg_t
01079 {
01080 public:
01081 msg_impl_t(const char *n,
01082 unsigned short s,
01083 unsigned short f)
01084 :msg_t(n,s,f)
01085 {}
01086
01087 void set_item(pdata_item_t pit)
01088 {
01089 _pitem = pit;
01090 }
01091 };
01092 };
01093 };
01094
01095 #endif