// -*- c++ -*- /* * MICO --- an Open Source CORBA implementation * Copyright (c) 1997-2010 by The Mico Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * For more information, visit the MICO Home Page at * http://www.mico.org/ */ #ifndef __MICO_SEQUENCE_SPECIAL_H__ #define __MICO_SEQUENCE_SPECIAL_H__ /* * This file hosts special sequence definitions (for sequence of * strings or sequences of interfaces) whose mapping differs slightly * from that of ordinary sequences (the "T* data" constructor). The * template parameter T must be CORBA::String_var. The reason we can't * explicitely write this here is because CORBA::String_var is not * known at this time. */ //---Template for unbounded sequence of strings-------------------------- template class StringSequenceTmpl { public: typedef T &ElementType; // Needed in TSeqVar (see var.h) typedef TSeqVar > _var_type; private: std::vector vec; public: StringSequenceTmpl () {} StringSequenceTmpl (MICO_ULong maxval) { vec.reserve (maxval); } StringSequenceTmpl (MICO_ULong max, MICO_ULong length, char** value, MICO_Boolean rel = FALSE); StringSequenceTmpl (const StringSequenceTmpl &s) { vec = s.vec; } ~StringSequenceTmpl () { } void replace (MICO_ULong max, MICO_ULong length, char** value, MICO_Boolean rel = FALSE); StringSequenceTmpl &operator= (const StringSequenceTmpl &s) { vec = s.vec; return *this; } MICO_ULong maximum () const { return vec.capacity (); } MICO_Boolean release () const { // we always own the buffer return TRUE; } char **get_buffer (MICO_Boolean orphan = FALSE) { // XXX assert (0); return 0; } const char **get_buffer () const { // XXX assert (0); return 0; } void length (MICO_ULong l); MICO_ULong length () const; T& operator[] (MICO_ULong idx); const T &operator[] (MICO_ULong idx) const; static char **allocbuf (MICO_ULong len) { return new char*[len]; } static void freebuf (char **b) { delete[] b; } #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC <= 0x5010 ) friend MICO_Boolean operator== (const StringSequenceTmpl &v1, const StringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif }; template StringSequenceTmpl::StringSequenceTmpl (MICO_ULong maxval, MICO_ULong lengthval, char** value, MICO_Boolean rel) { assert (lengthval <= maxval); vec.reserve (maxval); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const char *)value[i] ); } } } template void StringSequenceTmpl::replace (MICO_ULong maxval, MICO_ULong lengthval, char** value, MICO_Boolean rel) { assert (lengthval <= maxval); vec.erase (vec.begin(), vec.end()); vec.reserve (maxval); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const char *)value[i] ); } } } template void StringSequenceTmpl::length (MICO_ULong l) { if (l < vec.size ()) { vec.erase (vec.begin() + l, vec.end()); } else if (l > vec.size()) { T t; // the (long) cast is needed for SGI STL vec.insert (vec.end(), long(l - vec.size()), t); } } template inline MICO_ULong StringSequenceTmpl::length () const { // The MICO_ULong cast is needed for Win64/VC++ 10.0 return (MICO_ULong)vec.size (); } template inline T& StringSequenceTmpl::operator[] (MICO_ULong idx) { return vec[idx]; } template inline const T& StringSequenceTmpl::operator[] (MICO_ULong idx) const { return vec[idx]; } #if !defined( __SUNPRO_CC ) || ( __SUNPRO_CC > 0x5010 ) template MICO_Boolean operator== (const StringSequenceTmpl &v1, const StringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif //---Template for bounded sequence of strings---------------------------- template class BoundedStringSequenceTmpl { public: typedef T &ElementType; // Needed in TSeqVar (see var.h) private: std::vector vec; public: BoundedStringSequenceTmpl () { vec.reserve (max); } BoundedStringSequenceTmpl (MICO_ULong length, char** value, MICO_Boolean rel = TRUE); BoundedStringSequenceTmpl (const BoundedStringSequenceTmpl &s) { vec = s.vec; } ~BoundedStringSequenceTmpl () { } void replace (MICO_ULong length, char** value, MICO_Boolean rel = TRUE); BoundedStringSequenceTmpl &operator= (const BoundedStringSequenceTmpl &s) { vec = s.vec; return *this; } MICO_ULong maximum () const { return max; } MICO_Boolean release () const { // we always own the buffer return TRUE; } char **get_buffer (MICO_Boolean orphan = FALSE) { // XXX assert (0); return 0; } const char **get_buffer () const { // XXX assert (0); return 0; } void length (MICO_ULong l); MICO_ULong length () const { return vec.size (); } T &operator[] (MICO_ULong idx) { return vec[idx]; } const T &operator[] (MICO_ULong idx) const { return vec[idx]; } static char **allocbuf (MICO_ULong len) { return new char*[len]; } static void freebuf (char **b) { delete[] b; } #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC <= 0x5010 ) friend MICO_Boolean operator== (const BoundedStringSequenceTmpl &v1, const BoundedStringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif }; template BoundedStringSequenceTmpl::BoundedStringSequenceTmpl (MICO_ULong lengthval, char** value, MICO_Boolean rel) { assert (lengthval <= max); vec.reserve (max); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const char *)value[i] ); } } } template void BoundedStringSequenceTmpl::replace (MICO_ULong lengthval, char** value, MICO_Boolean rel) { assert (lengthval <= max); vec.erase (vec.begin(), vec.end()); vec.reserve (max); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const char *)value[i] ); } } } template void BoundedStringSequenceTmpl::length (MICO_ULong l) { assert (l <= max); if (l < vec.size ()) { vec.erase (vec.begin() + l, vec.end()); } else if (l > vec.size()) { T t; vec.insert (vec.end(), long(l - vec.size()), t); } } #if !defined( __SUNPRO_CC ) || ( __SUNPRO_CC > 0x5010 ) template MICO_Boolean operator== (const BoundedStringSequenceTmpl &v1, const BoundedStringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif //---Template for unbounded sequence of wstrings-------------------------- template class WStringSequenceTmpl { public: typedef T &ElementType; // Needed in TSeqVar (see var.h) typedef TSeqVar > _var_type; private: std::vector vec; public: WStringSequenceTmpl () {} WStringSequenceTmpl (MICO_ULong maxval) { vec.reserve (maxval); } WStringSequenceTmpl (MICO_ULong max, MICO_ULong length, wchar_t** value, MICO_Boolean rel = FALSE); WStringSequenceTmpl (const WStringSequenceTmpl &s) { vec = s.vec; } ~WStringSequenceTmpl () { } void replace (MICO_ULong max, MICO_ULong length, wchar_t** value, MICO_Boolean rel = FALSE); WStringSequenceTmpl &operator= (const WStringSequenceTmpl &s) { vec = s.vec; return *this; } MICO_ULong maximum () const { return vec.capacity (); } MICO_Boolean release () const { // we always own the buffer return TRUE; } wchar_t **get_buffer (MICO_Boolean orphan = FALSE) { // XXX assert (0); return 0; } const wchar_t **get_buffer () const { // XXX assert (0); return 0; } void length (MICO_ULong l); MICO_ULong length () const; T& operator[] (MICO_ULong idx); const T &operator[] (MICO_ULong idx) const; static wchar_t **allocbuf (MICO_ULong len) { return new wchar_t*[len]; } static void freebuf (wchar_t **b) { delete[] b; } #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC <= 0x5010 ) friend MICO_Boolean operator== (const WStringSequenceTmpl &v1, const WStringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif }; template WStringSequenceTmpl::WStringSequenceTmpl (MICO_ULong maxval, MICO_ULong lengthval, wchar_t** value, MICO_Boolean rel) { assert (lengthval <= maxval); vec.reserve (maxval); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const wchar_t *)value[i] ); } } } template void WStringSequenceTmpl::replace (MICO_ULong maxval, MICO_ULong lengthval, wchar_t** value, MICO_Boolean rel) { assert (lengthval <= maxval); vec.erase (vec.begin(), vec.end()); vec.reserve (maxval); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const wchar_t *)value[i] ); } } } template void WStringSequenceTmpl::length (MICO_ULong l) { if (l < vec.size ()) { vec.erase (vec.begin() + l, vec.end()); } else if (l > vec.size()) { T t; // the (long) cast is needed for SGI STL vec.insert (vec.end(), long(l - vec.size()), t); } } template inline MICO_ULong WStringSequenceTmpl::length () const { // The MICO_ULong cast is needed for Win64/VC++ 10.0 return (MICO_ULong)vec.size(); } template inline T & WStringSequenceTmpl::operator[] (MICO_ULong idx) { return vec[idx]; } template inline const T & WStringSequenceTmpl::operator[] (MICO_ULong idx) const { return vec[idx]; } #if !defined( __SUNPRO_CC ) || ( __SUNPRO_CC > 0x5010 ) template MICO_Boolean operator== (const WStringSequenceTmpl &v1, const WStringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif //---Template for bounded sequence of wstrings---------------------------- template class BoundedWStringSequenceTmpl { public: typedef T &ElementType; // Needed in TSeqVar (see var.h) private: std::vector vec; public: BoundedWStringSequenceTmpl () { vec.reserve (max); } BoundedWStringSequenceTmpl (MICO_ULong length, wchar_t** value, MICO_Boolean rel = TRUE); BoundedWStringSequenceTmpl (const BoundedWStringSequenceTmpl &s) { vec = s.vec; } ~BoundedWStringSequenceTmpl () { } void replace (MICO_ULong length, wchar_t** value, MICO_Boolean rel = TRUE); BoundedWStringSequenceTmpl &operator= (const BoundedWStringSequenceTmpl &s) { vec = s.vec; return *this; } MICO_ULong maximum () const { return max; } MICO_Boolean release () const { // we always own the buffer return TRUE; } wchar_t **get_buffer (MICO_Boolean orphan = FALSE) { // XXX assert (0); return 0; } const wchar_t **get_buffer () const { // XXX assert (0); return 0; } void length (MICO_ULong l); MICO_ULong length () const { return vec.size (); } T &operator[] (MICO_ULong idx) { return vec[idx]; } const T &operator[] (MICO_ULong idx) const { return vec[idx]; } static wchar_t **allocbuf (MICO_ULong len) { return new wchar_t*[len]; } static void freebuf (wchar_t **b) { delete[] b; } #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC <= 0x5010 ) friend MICO_Boolean operator== (const BoundedWStringSequenceTmpl &v1, const BoundedWStringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif }; template BoundedWStringSequenceTmpl::BoundedWStringSequenceTmpl (MICO_ULong lengthval, wchar_t** value, MICO_Boolean rel) { assert (lengthval <= max); vec.reserve (max); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const wchar_t *)value[i] ); } } } template void BoundedWStringSequenceTmpl::replace (MICO_ULong lengthval, wchar_t** value, MICO_Boolean rel) { assert (lengthval <= max); vec.erase (vec.begin(), vec.end()); vec.reserve (max); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( (const wchar_t *)value[i] ); } } } template void BoundedWStringSequenceTmpl::length (MICO_ULong l) { assert (l <= max); if (l < vec.size ()) { vec.erase (vec.begin() + l, vec.end()); } else if (l > vec.size()) { T t; vec.insert (vec.end(), long(l - vec.size()), t); } } #if !defined( __SUNPRO_CC ) || ( __SUNPRO_CC > 0x5010 ) template MICO_Boolean operator== (const BoundedWStringSequenceTmpl &v1, const BoundedWStringSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif //---Template for unbounded sequence of interfaces----------------------- template class IfaceSequenceTmpl { public: typedef T &ElementType; // Needed in TSeqVar (see var.h) typedef TSeqVar > _var_type; private: std::vector vec; public: IfaceSequenceTmpl () {} IfaceSequenceTmpl (MICO_ULong maxval) { vec.reserve (maxval); } IfaceSequenceTmpl (MICO_ULong max, MICO_ULong length, T_ptr* value, MICO_Boolean rel = FALSE); IfaceSequenceTmpl (const IfaceSequenceTmpl &s) { vec = s.vec; } ~IfaceSequenceTmpl () { } void replace (MICO_ULong max, MICO_ULong length, T_ptr* value, MICO_Boolean rel = FALSE); IfaceSequenceTmpl &operator= (const IfaceSequenceTmpl &s) { vec = s.vec; return *this; } MICO_ULong maximum () const { return vec.capacity (); } MICO_Boolean release () const { // we always own the buffer return TRUE; } T_ptr *get_buffer (MICO_Boolean orphan = FALSE) { // XXX assert (0); return 0; } const T_ptr *get_buffer () const { // XXX assert (0); return 0; } void length (MICO_ULong l); MICO_ULong length () const; T &operator[] (MICO_ULong idx); const T& operator[] (MICO_ULong idx) const; static T_ptr *allocbuf (MICO_ULong len) { return new T_ptr[len]; } static void freebuf (T_ptr *b) { delete[] b; } #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC <= 0x5010 ) friend MICO_Boolean operator== (const IfaceSequenceTmpl &v1, const IfaceSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif }; template IfaceSequenceTmpl::IfaceSequenceTmpl (MICO_ULong maxval, MICO_ULong lengthval, T_ptr* value, MICO_Boolean rel) { assert (lengthval <= maxval); vec.reserve (maxval); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( T::duplicate (value[i]) ); } } } template void IfaceSequenceTmpl::replace (MICO_ULong maxval, MICO_ULong lengthval, T_ptr* value, MICO_Boolean rel) { assert (lengthval <= maxval); vec.erase (vec.begin(), vec.end()); vec.reserve (maxval); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( T::duplicate (value[i]) ); } } } template void IfaceSequenceTmpl::length (MICO_ULong l) { if (l < vec.size ()) { vec.erase (vec.begin() + l, vec.end()); } else if (l > vec.size()) { T t; // the (long) cast is needed for SGI STL vec.insert (vec.end(), long(l - vec.size()), t); } } template inline MICO_ULong IfaceSequenceTmpl::length () const { // The MICO_ULong cast is needed for Win64/VC++ 10.0 return (MICO_ULong)vec.size (); } template inline T & IfaceSequenceTmpl::operator[] (MICO_ULong idx) { return vec[idx]; } template inline const T & IfaceSequenceTmpl::operator[] (MICO_ULong idx) const { return vec[idx]; } #if !defined( __SUNPRO_CC ) || ( __SUNPRO_CC > 0x5010 ) template MICO_Boolean operator== (const IfaceSequenceTmpl &v1, const IfaceSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!v1[_i]->_is_equivalent (v2[_i])) return FALSE; } return TRUE; } #endif //---Template for bounded sequence of interfaces------------------------- template class BoundedIfaceSequenceTmpl { public: typedef T &ElementType; // Needed in TSeqVar (see var.h) private: std::vector vec; public: BoundedIfaceSequenceTmpl () { vec.reserve (max); } BoundedIfaceSequenceTmpl (MICO_ULong length, T_ptr* value, MICO_Boolean rel = TRUE); BoundedIfaceSequenceTmpl (const BoundedIfaceSequenceTmpl &s) { vec = s.vec; } ~BoundedIfaceSequenceTmpl () { } void replace (MICO_ULong length, T_ptr* value, MICO_Boolean rel = TRUE); BoundedIfaceSequenceTmpl &operator= (const BoundedIfaceSequenceTmpl &s) { vec = s.vec; return *this; } MICO_ULong maximum () const { return max; } MICO_Boolean release () const { // we always own the buffer return TRUE; } T_ptr* get_buffer (MICO_Boolean orphan = FALSE) { // XXX assert (0); return 0; } const T_ptr* get_buffer () const { // XXX assert (0); return 0; } void length (MICO_ULong l); MICO_ULong length () const { return vec.size (); } T &operator[] (MICO_ULong idx) { return vec[idx]; } const T &operator[] (MICO_ULong idx) const { return vec[idx]; } static T_ptr *allocbuf (MICO_ULong len) { return new T_ptr[len]; } static void freebuf (T_ptr *b) { delete[] b; } #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC <= 0x5010 ) friend MICO_Boolean operator== (const BoundedIfaceSequenceTmpl &v1, const BoundedIfaceSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!(v1[_i] == v2[_i])) return FALSE; } return TRUE; } #endif }; template BoundedIfaceSequenceTmpl:: BoundedIfaceSequenceTmpl (MICO_ULong lengthval, T_ptr* value, MICO_Boolean rel) { assert (lengthval <= max); vec.reserve (max); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( T::duplicate (value[i]) ); } } } template void BoundedIfaceSequenceTmpl::replace (MICO_ULong lengthval, T_ptr* value, MICO_Boolean rel) { assert (lengthval <= max); vec.erase (vec.begin(), vec.end()); vec.reserve (max); for( MICO_ULong i = 0; i < lengthval; i++ ) { if (rel) { vec.push_back( value[i] ); } else { vec.push_back( T::duplicate (value[i]) ); } } } template void BoundedIfaceSequenceTmpl::length (MICO_ULong l) { assert (l <= max); if (l < vec.size ()) { vec.erase (vec.begin() + l, vec.end()); } else if (l > vec.size()) { T t; vec.insert (vec.end(), long(l - vec.size()), t); } } #if !defined( __SUNPRO_CC ) || ( __SUNPRO_CC > 0x5010 ) template MICO_Boolean operator== (const BoundedIfaceSequenceTmpl &v1, const BoundedIfaceSequenceTmpl &v2) { if (v1.length() != v2.length()) return FALSE; for (MICO_ULong _i = 0; _i < v1.length(); ++_i) { if (!v1[_i]->_is_equivalent (v2[_i])) return FALSE; } return TRUE; } #endif #endif