2 //=============================================================================
6 * Header file for the CORBA string types.
8 * @author DOC Group at Wash U, UCI, and Vanderbilt U.
10 //=============================================================================
12 #ifndef TAO_CORBA_STRING_H
13 #define TAO_CORBA_STRING_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "tao/TAO_Export.h"
18 #include "tao/Basic_Types.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "tao/String_Traits_Base_T.h"
25 // For the (W)String_var and (W)String_out iostream operators.
26 #include "ace/iosfwd.h"
30 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
34 template <typename charT
> class String_Manager_T
; // Forward declaration.
35 typedef String_Manager_T
<CORBA::Char
> String_Manager
;
36 typedef String_Manager_T
<CORBA::WChar
> WString_Manager
;
44 * Provides automatic deallocation of storage for the string once it
47 template <typename charT
>
51 typedef charT character_type
;
52 typedef TAO::details::string_traits_base
<character_type
> s_traits
;
54 /// Default constructor.
55 inline String_var () : ptr_ (0)
59 /// Constructor, owns p.
60 inline String_var (character_type
*p
) : ptr_ (p
)
64 /// Constructor. Makes a copy of p.
65 inline String_var (const character_type
*p
) : ptr_ (s_traits::duplicate (p
))
70 inline String_var (String_var
<charT
> const &s
) : ptr_(s_traits::duplicate(s
.ptr_
))
77 s_traits::release (this->ptr_
);
80 /// Assignment operator.
81 inline String_var
&operator= (character_type
*p
)
83 String_var
<charT
> tmp (p
);
84 std::swap (this->ptr_
, tmp
.ptr_
);
88 /// Assignment to a const char*. Makes a copy.
89 inline String_var
&operator= (const character_type
*p
)
91 String_var
<charT
> tmp (p
);
92 std::swap (this->ptr_
, tmp
.ptr_
);
96 /// Assignment operator.
97 inline String_var
&operator= (String_var
<character_type
> const &s
)
99 String_var
<charT
> tmp (s
);
100 std::swap (this->ptr_
, tmp
.ptr_
);
104 /// Spec-defined read/write version.
105 inline operator character_type
*&()
110 /// Only read privileges.
111 inline operator const character_type
*() const
116 /// Allows access and modification using an slot.
117 inline character_type
&operator[] (CORBA::ULong slot
)
119 // We need to verify bounds else raise some exception.
120 return this->ptr_
[slot
];
123 /// Allows only accessing thru an slot.
124 inline character_type
operator[] (CORBA::ULong slot
) const
126 // We need to verify bounds else raise some exception.
127 return this->ptr_
[slot
];
130 /// For in parameter.
131 inline const character_type
*in () const
136 /// For inout parameter.
137 inline character_type
*&inout ()
142 /// For out parameter.
143 inline character_type
*&out ()
145 s_traits::release (this->ptr_
);
150 /// For string of return type.
151 inline character_type
*_retn ()
153 character_type
*temp
= this->ptr_
;
160 character_type
*ptr_
;
168 * To support the memory management for "out" parameter passing
171 template <typename charT
>
175 typedef charT character_type
;
176 typedef TAO::details::string_traits_base
<character_type
> s_traits
;
177 typedef typename
s_traits::string_mgr string_mgr
;
179 /// Construction from a reference to a string.
180 inline String_out (character_type
*&p
) : ptr_ (p
)
185 /// Construction from a var.
186 inline String_out (String_var
<character_type
> &p
) : ptr_ (p
.out ())
190 /// Construction from a TAO::String_Manager.
191 inline String_out (string_mgr
&p
) : ptr_ (p
.out ())
195 /// Copy constructor.
196 inline String_out (const String_out
<charT
> &s
) : ptr_ (s
.ptr_
)
200 /// Assignment from a string_out.
201 inline String_out
&operator= (String_out
<charT
> const &s
)
207 /// Assignment from a string.
208 inline String_out
&operator= (character_type
*p
)
214 /// Assignment from a constant char*.
215 inline String_out
& operator= (const character_type
* p
)
217 this->ptr_
= s_traits::duplicate (p
);
222 inline operator character_type
*&()
227 /// Return underlying instance.
228 inline character_type
*&ptr ()
235 character_type
*&ptr_
;
237 // Assignment from _var disallowed
238 void operator= (const typename
s_traits::string_var
&);
242 * @struct TAO-specific @c {W}String_var Equality Functor
244 * This functor exist to simplify usage of @c {W}String_var in
247 struct String_Var_Equal_To
249 bool operator() (CORBA::String_var
const & lhs
,
250 CORBA::String_var
const & rhs
) const;
252 bool operator() (CORBA::WString_var
const & lhs
,
253 CORBA::WString_var
const & rhs
) const;
259 typedef TAO::String_var
<char> String_var
;
260 typedef TAO::String_out
<char> String_out
;
261 typedef TAO::String_var
<CORBA::WChar
> WString_var
;
262 typedef TAO::String_out
<CORBA::WChar
> WString_out
;
266 # if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
269 operator<< (ostream
&, const CORBA::String_var
&);
271 operator>> (istream
&, CORBA::String_var
&);
273 operator<< (ostream
&, CORBA::String_out
&);
275 operator>> (istream
&, CORBA::String_out
&);
277 # ifndef ACE_HAS_CPP20
279 operator<< (ostream
&, const CORBA::WString_var
&);
281 operator>> (istream
&, CORBA::WString_var
&);
283 operator<< (ostream
&, CORBA::WString_out
&);
285 operator>> (istream
&, CORBA::WString_out
&);
286 # endif /* ACE_HAS_CPP20 */
288 # endif /* ACE_LACKS_IOSTREAM_TOTALLY */
290 TAO_END_VERSIONED_NAMESPACE_DECL
292 #if defined (__ACE_INLINE__)
293 # include "tao/CORBA_String.inl"
294 #endif /* ! __ACE_INLINE__ */
296 #include /**/ "ace/post.h"
298 #endif /* TAO_CORBA_STRING_H */