Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / String_Manager_T.h
blob9a0905bff5757cc2726f5810317cca62929bb86a
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file String_Manager_T.h
7 * @author Johnny Willemsen <jwillemsen@remedy.nl>
8 */
9 //=============================================================================
11 #ifndef TAO_STRING_MANAGER_T
12 #define TAO_STRING_MANAGER_T
14 #include /**/ "ace/pre.h"
16 #include /**/ "tao/TAO_Export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/OS_NS_string.h"
23 #include "tao/Basic_Types.h"
24 #include "tao/String_Traits_Base_T.h"
26 #include <algorithm>
28 /****************************************************************/
30 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
32 namespace TAO
34 template <typename charT>
35 class String_Manager_T
37 public:
38 typedef charT character_type;
39 typedef TAO::details::string_traits_base <charT> s_traits;
41 /// Default CTOR will initialize the underlying ptr_ to empty string.
42 inline String_Manager_T () : ptr_ (s_traits::default_initializer())
46 /// Copy constructor
47 inline String_Manager_T (const String_Manager_T<charT> &rhs) :
48 ptr_ (s_traits::duplicate (rhs.ptr_))
52 /// Constructor from const char* makes a copy.
53 inline String_Manager_T (const character_type *s) :
54 ptr_ (s_traits::duplicate (s))
58 /// Destructor
59 inline ~String_Manager_T () {
60 s_traits::release (this->ptr_);
63 /// Assignment from another managed type
64 inline String_Manager_T &operator= (const String_Manager_T<charT> &rhs) {
65 // Strongly exception safe by means of copy and non-throwing swap
66 // technique.
67 String_Manager_T <character_type> tmp (rhs);
68 std::swap (this->ptr_, tmp.ptr_);
69 return *this;
72 /// Assignment from var type will make a copy
73 inline String_Manager_T &operator= (const typename s_traits::string_var& value) {
74 // Strongly exception safe by means of copy and non-throwing swap
75 // technique.
76 String_Manager_T <character_type> tmp (value.in ());
77 std::swap (this->ptr_, tmp.ptr_);
78 return *this;
81 /// Assignment from a constant * will make a copy
82 inline String_Manager_T &operator= (const character_type *p) {
83 // Strongly exception safe by means of copy and non-throwing swap
84 // technique.
85 String_Manager_T <character_type> tmp (p);
86 std::swap (this->ptr_, tmp.ptr_);
87 return *this;
90 /// Assignment from char* will not make a copy. The String_Manager_T will now
91 /// own the string.
92 inline String_Manager_T &operator= (character_type *p) {
93 s_traits::release (this->ptr_);
94 this->ptr_ = p;
95 return *this;
98 /// Cast (read-only)
99 inline operator const character_type*() const {
100 return this->ptr_;
103 /// For in parameter.
104 inline const character_type *in () const {
105 return this->ptr_;
108 /// For inout parameter.
109 inline character_type *&inout () {
110 return this->ptr_;
113 /// for out parameter.
114 inline character_type *&out () {
115 s_traits::release (this->ptr_);
116 this->ptr_ = 0;
117 return this->ptr_;
120 /// For string of return type.
121 inline character_type *_retn () {
122 character_type *temp = this->ptr_;
123 this->ptr_ = 0;
124 return temp;
127 private:
128 /// The underlying string
129 character_type *ptr_;
132 typedef TAO::String_Manager_T<CORBA::Char> String_Manager;
133 typedef TAO::String_Manager_T<CORBA::WChar> WString_Manager;
136 inline bool operator< (const TAO::String_Manager &lhs, const TAO::String_Manager &rhs)
138 return ACE_OS::strcmp (lhs.in(), rhs.in ()) < 0;
141 inline bool operator< (const TAO::WString_Manager &lhs, const TAO::WString_Manager &rhs)
143 return ACE_OS::strcmp (lhs.in(), rhs.in ()) < 0;
146 TAO_END_VERSIONED_NAMESPACE_DECL
148 #include /**/ "ace/post.h"
149 #endif /* TAO_STRING_MANAGER_T */