CORBA_String.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //=============================================================================
00003 /**
00004  *  @file    CORBA_String.h
00005  *
00006  *  CORBA_String.h,v 1.17 2006/04/19 08:34:34 jwillemsen Exp
00007  *
00008  *  Header file for the CORBA string types.
00009  *
00010  *  @author DOC Group at Wash U, UCI, and Vanderbilt U.
00011  */
00012 //=============================================================================
00013 
00014 #ifndef TAO_CORBA_STRING_H
00015 #define TAO_CORBA_STRING_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "tao/TAO_Export.h"
00020 #include "tao/Basic_Types.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "tao/String_Traits_Base_T.h"
00027 // For the (W)String_var and (W)String_out iostream operators.
00028 #include "ace/iosfwd.h"
00029 
00030 #include <algorithm>
00031 
00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 namespace TAO
00035 {
00036   template <typename charT> class String_Manager_T;  // Forward declaration.
00037   typedef String_Manager_T<CORBA::Char> String_Manager;
00038   typedef String_Manager_T<CORBA::WChar> WString_Manager;
00039 }
00040 
00041 namespace TAO
00042 {
00043   /**
00044    * @class String_var
00045    *
00046    * Provides automatic deallocation of storage for the string once it
00047    * goes out of scope.
00048    */
00049   template <typename charT>
00050   class String_var
00051   {
00052   public:
00053     typedef charT character_type;
00054     typedef TAO::details::string_traits_base <character_type> s_traits;
00055 
00056     /// Default constructor.
00057     inline String_var (void) : ptr_ (0)
00058     {
00059     }
00060 
00061     /// Constructor, owns p.
00062     inline String_var (character_type *p) : ptr_ (p)
00063     {
00064     }
00065 
00066     /// Constructor. Makes a copy of p.
00067     inline String_var (const character_type *p) : ptr_ (s_traits::duplicate (p))
00068     {
00069     }
00070 
00071     /// Copy constructor.
00072     inline String_var (String_var<charT> const &s) : ptr_(s_traits::duplicate(s.ptr_))
00073     {
00074     }
00075 
00076     /// Destructor.
00077     inline ~String_var (void)
00078     {
00079       s_traits::release (this->ptr_);
00080     }
00081 
00082     /// Assignment operator.
00083     inline String_var &operator= (character_type *p)
00084     {
00085       String_var <charT> tmp (p);
00086       std::swap (this->ptr_, tmp.ptr_);
00087       return *this;
00088     }
00089 
00090     /// Assignment to a const char*.  Makes a copy.
00091     inline String_var &operator= (const character_type *p)
00092     {
00093       String_var <charT> tmp (p);
00094       std::swap (this->ptr_, tmp.ptr_);
00095       return *this;
00096     }
00097 
00098     /// Assignment operator.
00099     inline String_var &operator= (String_var<character_type> const &s)
00100     {
00101       String_var <charT> tmp (s);
00102       std::swap (this->ptr_, tmp.ptr_);
00103       return *this;
00104     }
00105 
00106     /// Spec-defined read/write version.
00107     inline operator character_type *&()
00108     {
00109       return this->ptr_;
00110     }
00111 
00112     /// Only read privileges.
00113     inline operator const character_type *() const
00114     {
00115       return this->ptr_;
00116     }
00117 
00118     /// Allows access and modification using an slot.
00119     inline character_type &operator[] (CORBA::ULong slot)
00120     {
00121       // We need to verify bounds else raise some exception.
00122       return this->ptr_[slot];
00123     }
00124 
00125     /// Allows only accessing thru an slot.
00126     inline character_type operator[] (CORBA::ULong slot) const
00127     {
00128       // We need to verify bounds else raise some exception.
00129       return this->ptr_[slot];
00130     }
00131 
00132     /// For in parameter.
00133     inline const character_type *in (void) const
00134     {
00135       return this->ptr_;
00136     }
00137 
00138     /// For inout parameter.
00139     inline character_type *&inout (void)
00140     {
00141       return this->ptr_;
00142     }
00143 
00144     /// For out parameter.
00145     inline character_type *&out (void)
00146     {
00147       s_traits::release (this->ptr_);
00148       this->ptr_ = 0;
00149       return this->ptr_;
00150     }
00151 
00152     /// For string of return type.
00153     inline character_type *_retn (void)
00154     {
00155       character_type *temp = this->ptr_;
00156       this->ptr_ = 0;
00157       return temp;
00158     }
00159 
00160   private:
00161     /// Instance.
00162     character_type *ptr_;
00163   };
00164 
00165   /**
00166    * @class String_out
00167    *
00168    * @brief String_out
00169    *
00170    * To support the memory management for "out" parameter passing
00171    * mode.
00172    */
00173   template <typename charT>
00174   class String_out
00175   {
00176   public:
00177     typedef charT character_type;
00178     typedef TAO::details::string_traits_base <character_type> s_traits;
00179     typedef typename s_traits::string_mgr string_mgr;
00180 
00181     /// Construction from a reference to a string.
00182     inline String_out (character_type *&p) : ptr_ (p)
00183     {
00184       this->ptr_ = 0;
00185     }
00186 
00187     /// Construction from a var.
00188     inline String_out (String_var <character_type> &p) : ptr_ (p.out ())
00189     {
00190     }
00191 
00192     /// Construction from a TAO::String_Manager.
00193     inline String_out (string_mgr &p) : ptr_ (p.out ())
00194     {
00195     }
00196 
00197     /// Copy constructor.
00198     inline String_out (const String_out<charT> &s) : ptr_ (s.ptr_)
00199     {
00200     }
00201 
00202     /// Assignment from a string_out.
00203     inline String_out &operator= (String_out<charT> const &s)
00204     {
00205       this->ptr_ = s.ptr_;
00206       return *this;
00207     }
00208 
00209     /// Assignment from a string.
00210     inline String_out &operator= (character_type *p)
00211     {
00212       this->ptr_ = p;
00213       return *this;
00214     }
00215 
00216     /// Assignment from a constant char*.
00217     inline String_out& operator= (const character_type* p)
00218     {
00219       this->ptr_ = s_traits::duplicate (p);
00220       return *this;
00221     }
00222 
00223     /// Cast.
00224     inline operator character_type *&()
00225     {
00226       return this->ptr_;
00227     }
00228 
00229     /// Return underlying instance.
00230     inline character_type *&ptr (void)
00231     {
00232       return this->ptr_;
00233     }
00234 
00235   private:
00236     /// Instance.
00237     character_type *&ptr_;
00238 
00239     // Assignment from _var disallowed
00240     void operator= (const typename s_traits::string_var &);
00241   };
00242 
00243   /**
00244    * @struct TAO-specific @c {W}String_var Equality Functor
00245    *
00246    * This functor exist to simplify usage of @c {W}String_var in
00247    * containers.
00248    */
00249   struct String_Var_Equal_To
00250   {
00251     bool operator() (CORBA::String_var const & lhs,
00252                      CORBA::String_var const & rhs) const;
00253 
00254     bool operator() (CORBA::WString_var const & lhs,
00255                      CORBA::WString_var const & rhs) const;
00256   };
00257 }
00258 
00259 namespace CORBA
00260 {
00261   typedef TAO::String_var <char> String_var;
00262   typedef TAO::String_out <char> String_out;
00263   typedef TAO::String_var <CORBA::WChar> WString_var;
00264   typedef TAO::String_out <CORBA::WChar> WString_out;
00265 }
00266 
00267 
00268 # if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00269 
00270 TAO_Export ostream &
00271 operator<< (ostream &, const CORBA::String_var &);
00272 TAO_Export istream &
00273 operator>> (istream &, CORBA::String_var &);
00274 TAO_Export ostream &
00275 operator<< (ostream &, CORBA::String_out &);
00276 TAO_Export istream &
00277 operator>> (istream &, CORBA::String_out &);
00278 TAO_Export ostream &
00279 operator<< (ostream &, const CORBA::WString_var &);
00280 TAO_Export istream &
00281 operator>> (istream &, CORBA::WString_var &);
00282 TAO_Export ostream &
00283 operator<< (ostream &, CORBA::WString_out &);
00284 TAO_Export istream &
00285 operator>> (istream &, CORBA::WString_out &);
00286 
00287 # endif /* ACE_LACKS_IOSTREAM_TOTALLY */
00288 
00289 TAO_END_VERSIONED_NAMESPACE_DECL
00290 
00291 #if defined (__ACE_INLINE__)
00292 # include "tao/CORBA_String.inl"
00293 #endif /* ! __ACE_INLINE__ */
00294 
00295 #include /**/ "ace/post.h"
00296 
00297 #endif  /* TAO_CORBA_STRING_H */

Generated on Thu Nov 9 11:54:09 2006 for TAO by doxygen 1.3.6