Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / CORBA_String.h
blob2338c9a03a43bcddb1bce9db6a43039ff13f9f0a
1 // -*- C++ -*-
2 //=============================================================================
3 /**
4 * @file CORBA_String.h
6 * Header file for the CORBA string types.
8 * @author DOC Group at Wash U, UCI, and Vanderbilt U.
9 */
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)
21 # 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"
28 #include <algorithm>
30 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
32 namespace TAO
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;
39 namespace TAO
41 /**
42 * @class String_var
44 * Provides automatic deallocation of storage for the string once it
45 * goes out of scope.
47 template <typename charT>
48 class String_var
50 public:
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))
69 /// Copy constructor.
70 inline String_var (String_var<charT> const &s) : ptr_(s_traits::duplicate(s.ptr_))
74 /// Destructor.
75 inline ~String_var ()
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_);
85 return *this;
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_);
93 return *this;
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_);
101 return *this;
104 /// Spec-defined read/write version.
105 inline operator character_type *&()
107 return this->ptr_;
110 /// Only read privileges.
111 inline operator const character_type *() const
113 return this->ptr_;
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
133 return this->ptr_;
136 /// For inout parameter.
137 inline character_type *&inout ()
139 return this->ptr_;
142 /// For out parameter.
143 inline character_type *&out ()
145 s_traits::release (this->ptr_);
146 this->ptr_ = 0;
147 return this->ptr_;
150 /// For string of return type.
151 inline character_type *_retn ()
153 character_type *temp = this->ptr_;
154 this->ptr_ = 0;
155 return temp;
158 private:
159 /// Instance.
160 character_type *ptr_;
164 * @class String_out
166 * @brief String_out
168 * To support the memory management for "out" parameter passing
169 * mode.
171 template <typename charT>
172 class String_out
174 public:
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)
182 this->ptr_ = 0;
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)
203 this->ptr_ = s.ptr_;
204 return *this;
207 /// Assignment from a string.
208 inline String_out &operator= (character_type *p)
210 this->ptr_ = p;
211 return *this;
214 /// Assignment from a constant char*.
215 inline String_out& operator= (const character_type* p)
217 this->ptr_ = s_traits::duplicate (p);
218 return *this;
221 /// Cast.
222 inline operator character_type *&()
224 return this->ptr_;
227 /// Return underlying instance.
228 inline character_type *&ptr ()
230 return this->ptr_;
233 private:
234 /// Instance.
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
245 * containers.
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;
257 namespace CORBA
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)
268 TAO_Export ostream &
269 operator<< (ostream &, const CORBA::String_var &);
270 TAO_Export istream &
271 operator>> (istream &, CORBA::String_var &);
272 TAO_Export ostream &
273 operator<< (ostream &, CORBA::String_out &);
274 TAO_Export istream &
275 operator>> (istream &, CORBA::String_out &);
277 # ifndef ACE_HAS_CPP20
278 TAO_Export ostream &
279 operator<< (ostream &, const CORBA::WString_var &);
280 TAO_Export istream &
281 operator>> (istream &, CORBA::WString_var &);
282 TAO_Export ostream &
283 operator<< (ostream &, CORBA::WString_out &);
284 TAO_Export istream &
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 */