3 //=============================================================================
5 * @file String_Manager_T.h
7 * @author Johnny Willemsen <jwillemsen@remedy.nl>
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)
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"
28 /****************************************************************/
30 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
34 template <typename charT
>
35 class String_Manager_T
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())
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
))
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
67 String_Manager_T
<character_type
> tmp (rhs
);
68 std::swap (this->ptr_
, tmp
.ptr_
);
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
76 String_Manager_T
<character_type
> tmp (value
.in ());
77 std::swap (this->ptr_
, tmp
.ptr_
);
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
85 String_Manager_T
<character_type
> tmp (p
);
86 std::swap (this->ptr_
, tmp
.ptr_
);
90 /// Assignment from char* will not make a copy. The String_Manager_T will now
92 inline String_Manager_T
&operator= (character_type
*p
) {
93 s_traits::release (this->ptr_
);
99 inline operator const character_type
*() const {
103 /// For in parameter.
104 inline const character_type
*in () const {
108 /// For inout parameter.
109 inline character_type
*&inout () {
113 /// for out parameter.
114 inline character_type
*&out () {
115 s_traits::release (this->ptr_
);
120 /// For string of return type.
121 inline character_type
*_retn () {
122 character_type
*temp
= this->ptr_
;
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 */