ACE_NS_String Class Reference

This class and ACE_NS_Internal are used as Adapters to work with the Map_Manager. More...

#include <Local_Name_Space.h>

List of all members.

Public Member Functions

 ACE_NS_String (void)
 Default "no-op" constructor.
 ACE_NS_String (ACE_WCHAR_T *dst, const ACE_WCHAR_T *src, size_t len)
 Initialization method.
 ACE_NS_String (const ACE_NS_WString &)
 Converts an ACE_NS_WString to an ACE_NS_String;.
 ~ACE_NS_String (void)
 Destructor.
 operator ACE_NS_WString () const
 Converts an ACE_NS_String to fresh copy of an ACE_NS_WString;.
char * char_rep (void) const
 Return the ASCII character representation.
int strstr (const ACE_NS_String &) const
 Matches on substrings.
bool operator== (const ACE_NS_String &) const
 Compare an ACE_NS_String.
bool operator!= (const ACE_NS_String &) const
 Compare an ACE_NS_String.
size_t len (void) const
 Returns length of the string.
ACE_WCHAR_T * fast_rep (void) const
 Returns the underlying representation.
u_long hash (void) const
 Returns a hash value for this string.

Private Attributes

size_t len_
 Length of the string.
ACE_WCHAR_T * rep_
 This actually points into shared/persistent memory.
bool delete_rep_


Detailed Description

This class and ACE_NS_Internal are used as Adapters to work with the Map_Manager.

In order to work correctly, this class must be able to convert back and forth with <ACE_NS_WStrings>.

Definition at line 39 of file Local_Name_Space.h.


Constructor & Destructor Documentation

ACE_NS_String::ACE_NS_String ( void   ) 

Default "no-op" constructor.

Definition at line 50 of file Local_Name_Space.cpp.

References ACE_TRACE.

00051   : len_ (0),
00052     rep_ (0),
00053     delete_rep_ (false)
00054 {
00055   ACE_TRACE ("ACE_NS_String::ACE_NS_String");
00056 }

ACE_NS_String::ACE_NS_String ( ACE_WCHAR_T *  dst,
const ACE_WCHAR_T *  src,
size_t  len 
)

Initialization method.

Definition at line 116 of file Local_Name_Space.cpp.

References ACE_TRACE, and ACE_OS::memcpy().

00119   : len_ (bytes),
00120     rep_ (dst),
00121     delete_rep_ (false)
00122 {
00123   ACE_TRACE ("ACE_NS_String::ACE_NS_String");
00124   ACE_OS::memcpy (this->rep_, src, bytes);
00125 }

ACE_NS_String::ACE_NS_String ( const ACE_NS_WString  ) 

Converts an ACE_NS_WString to an ACE_NS_String;.

Definition at line 58 of file Local_Name_Space.cpp.

References ACE_TRACE.

00059   : len_ ((s.length () + 1) * sizeof (ACE_WCHAR_T)),
00060     rep_ (s.rep ()),
00061     delete_rep_ (true)
00062 {
00063   ACE_TRACE ("ACE_NS_String::ACE_NS_String");
00064 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_NS_String::~ACE_NS_String ( void   ) 

Destructor.

Definition at line 14 of file Local_Name_Space.cpp.

00015 {
00016   if (this->delete_rep_)
00017     delete [] this->rep_;
00018 }


Member Function Documentation

char * ACE_NS_String::char_rep ( void   )  const

Return the ASCII character representation.

Definition at line 42 of file Local_Name_Space.cpp.

References ACE_TRACE, ACE_WCHAR_T, and ACE_NS_WString::char_rep().

00043 {
00044   ACE_TRACE ("ACE_NS_String::char_rep");
00045   ACE_NS_WString w_string (this->rep_,
00046                            (this->len_ / sizeof (ACE_WCHAR_T)) - 1);
00047   return w_string.char_rep ();
00048 }

ACE_WCHAR_T * ACE_NS_String::fast_rep ( void   )  const

Returns the underlying representation.

Definition at line 21 of file Local_Name_Space.cpp.

References ACE_TRACE, and rep_.

00022 {
00023   ACE_TRACE ("ACE_NS_String::fast_rep");
00024   return this->rep_;
00025 }

u_long ACE_NS_String::hash ( void   )  const

Returns a hash value for this string.

Definition at line 128 of file Local_Name_Space.cpp.

References ACE::hash_pjw().

00129 {
00130   return ACE::hash_pjw
00131     (reinterpret_cast<char *> (const_cast<ACE_WCHAR_T *> (this->rep_)),
00132      this->len_);
00133 }

size_t ACE_NS_String::len ( void   )  const

Returns length of the string.

Definition at line 35 of file Local_Name_Space.cpp.

References ACE_TRACE, and len_.

Referenced by strstr().

00036 {
00037   ACE_TRACE ("ACE_NS_String::len");
00038   return this->len_;
00039 }

ACE_NS_String::operator ACE_NS_WString (  )  const

Converts an ACE_NS_String to fresh copy of an ACE_NS_WString;.

Definition at line 27 of file Local_Name_Space.cpp.

References ACE_TRACE, and ACE_WCHAR_T.

00028 {
00029   ACE_TRACE ("ACE_NS_String::operator ACE_NS_WString");
00030   return ACE_NS_WString (this->rep_,
00031                          (this->len_ / sizeof (ACE_WCHAR_T)) - 1);
00032 }

bool ACE_NS_String::operator!= ( const ACE_NS_String  )  const

Compare an ACE_NS_String.

Definition at line 110 of file Local_Name_Space.cpp.

References ACE_TRACE, and operator==().

00111 {
00112   ACE_TRACE ("ACE_NS_String::operator !=");
00113   return !this->operator == (s);
00114 }

bool ACE_NS_String::operator== ( const ACE_NS_String  )  const

Compare an ACE_NS_String.

Definition at line 101 of file Local_Name_Space.cpp.

References ACE_TRACE, len_, ACE_OS::memcmp(), and rep_.

Referenced by operator!=().

00102 {
00103   ACE_TRACE ("ACE_NS_String::operator ==");
00104   return this->len_ == s.len_
00105     && ACE_OS::memcmp ((void *) this->rep_,
00106                        (void *) s.rep_, this->len_) == 0;
00107 }

int ACE_NS_String::strstr ( const ACE_NS_String  )  const

Matches on substrings.

Definition at line 67 of file Local_Name_Space.cpp.

References ACE_TRACE, ACE_WCHAR_T, len(), len_, and rep_.

00068 {
00069   ACE_TRACE ("ACE_NS_String::strstr");
00070 
00071   if (this->len_ < s.len_)
00072     // If they're larger than we are they can't be a substring of us!
00073     return -1;
00074   else if (this->len_ == s.len_)
00075     // Check if we're equal.
00076     return *this == s ? 0 : -1;
00077   else
00078     {
00079       // They're smaller than we are...
00080       const size_t len = (this->len_ - s.len_) / sizeof (ACE_WCHAR_T);
00081       const size_t pat_len = s.len_ / sizeof (ACE_WCHAR_T) - 1;
00082 
00083       for (size_t i = 0; i <= len; ++i)
00084         {
00085           size_t j;
00086 
00087           for (j = 0; j < pat_len; ++j)
00088             if (this->rep_[i + j] != s.rep_[j])
00089               break;
00090 
00091           if (j == pat_len)
00092             // Found a match!  Return the index.
00093             return ACE_Utils::truncate_cast<int> (i);
00094         }
00095 
00096       return -1;
00097     }
00098 }


Member Data Documentation

bool ACE_NS_String::delete_rep_ [private]

Should rep_ be deleted when destructed (only used for WString conversions)

Definition at line 90 of file Local_Name_Space.h.

size_t ACE_NS_String::len_ [private]

Length of the string.

Definition at line 83 of file Local_Name_Space.h.

Referenced by len(), operator==(), and strstr().

ACE_WCHAR_T* ACE_NS_String::rep_ [private]

This actually points into shared/persistent memory.

Definition at line 86 of file Local_Name_Space.h.

Referenced by fast_rep(), operator==(), and strstr().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:24 2010 for ACE by  doxygen 1.4.7