00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file String_Manager_T.h 00006 * 00007 * $Id: String_Manager_T.h 88065 2009-12-10 13:04:10Z johnnyw $ 00008 * 00009 * @author Johnny Willemsen <jwillemsen@remedy.nl> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_STRING_MANAGER_T 00014 #define TAO_STRING_MANAGER_T 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include /**/ "tao/TAO_Export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "ace/OS_NS_string.h" 00025 #include "tao/Basic_Types.h" 00026 #include "tao/String_Traits_Base_T.h" 00027 00028 #include <algorithm> 00029 00030 /****************************************************************/ 00031 00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00033 00034 namespace TAO 00035 { 00036 template <typename charT> 00037 class String_Manager_T 00038 { 00039 public: 00040 typedef charT character_type; 00041 typedef TAO::details::string_traits_base <charT> s_traits; 00042 00043 /// Default CTOR will initialize the underlying ptr_ to empty string. 00044 inline String_Manager_T (void) : ptr_ (s_traits::default_initializer()) 00045 { 00046 } 00047 00048 /// Copy constructor 00049 inline String_Manager_T (const String_Manager_T<charT> &rhs) : 00050 ptr_ (s_traits::duplicate (rhs.ptr_)) 00051 { 00052 } 00053 00054 /// Constructor from const char* makes a copy. 00055 inline String_Manager_T (const character_type *s) : 00056 ptr_ (s_traits::duplicate (s)) 00057 { 00058 } 00059 00060 /// Destructor 00061 inline ~String_Manager_T (void) { 00062 s_traits::release (this->ptr_); 00063 } 00064 00065 /// Assignment from another managed type 00066 inline String_Manager_T &operator= (const String_Manager_T<charT> &rhs) { 00067 // Strongly exception safe by means of copy and non-throwing swap 00068 // technique. 00069 String_Manager_T <character_type> tmp (rhs); 00070 std::swap (this->ptr_, tmp.ptr_); 00071 return *this; 00072 } 00073 00074 /// Assignment from var type will make a copy 00075 inline String_Manager_T &operator= (const typename s_traits::string_var& value) { 00076 // Strongly exception safe by means of copy and non-throwing swap 00077 // technique. 00078 String_Manager_T <character_type> tmp (value.in ()); 00079 std::swap (this->ptr_, tmp.ptr_); 00080 return *this; 00081 } 00082 00083 /// Assignment from a constant * will make a copy 00084 inline String_Manager_T &operator= (const character_type *p) { 00085 // Strongly exception safe by means of copy and non-throwing swap 00086 // technique. 00087 String_Manager_T <character_type> tmp (p); 00088 std::swap (this->ptr_, tmp.ptr_); 00089 return *this; 00090 } 00091 00092 /// Assignment from char* will not make a copy. The String_Manager_T will now 00093 /// own the string. 00094 inline String_Manager_T &operator= (character_type *p) { 00095 s_traits::release (this->ptr_); 00096 this->ptr_ = p; 00097 return *this; 00098 } 00099 00100 /// Cast (read-only) 00101 inline operator const character_type*() const { 00102 return this->ptr_; 00103 } 00104 00105 /// For in parameter. 00106 inline const character_type *in (void) const { 00107 return this->ptr_; 00108 } 00109 00110 /// For inout parameter. 00111 inline character_type *&inout (void) { 00112 return this->ptr_; 00113 } 00114 00115 /// for out parameter. 00116 inline character_type *&out (void) { 00117 s_traits::release (this->ptr_); 00118 this->ptr_ = 0; 00119 return this->ptr_; 00120 } 00121 00122 /// For string of return type. 00123 inline character_type *_retn (void) { 00124 character_type *temp = this->ptr_; 00125 this->ptr_ = 0; 00126 return temp; 00127 } 00128 00129 private: 00130 /// The underlying string 00131 character_type *ptr_; 00132 }; 00133 00134 typedef TAO::String_Manager_T<CORBA::Char> String_Manager; 00135 typedef TAO::String_Manager_T<CORBA::WChar> WString_Manager; 00136 } 00137 00138 00139 inline bool operator< (const TAO::String_Manager &lhs, const TAO::String_Manager &rhs) 00140 { 00141 return ACE_OS::strcmp (lhs.in(), rhs.in ()) < 0; 00142 } 00143 00144 00145 inline bool operator< (const TAO::WString_Manager &lhs, const TAO::WString_Manager &rhs) 00146 { 00147 return ACE_OS::strcmp (lhs.in(), rhs.in ()) < 0; 00148 } 00149 00150 TAO_END_VERSIONED_NAMESPACE_DECL 00151 00152 #include /**/ "ace/post.h" 00153 #endif /* TAO_STRING_MANAGER_T */