Version: 9.15.0
YACS::ENGINE::StringOnHeap Class Reference

#include <Any.hxx>

Collaboration diagram for YACS::ENGINE::StringOnHeap:

Private Member Functions

 StringOnHeap (const char *val)
 
 StringOnHeap (const char *val, std::size_t len)
 
 StringOnHeap (const std::string &val)
 
 StringOnHeap (char *val, Deallocator deAlloc)
 
bool operator== (const StringOnHeap &other) const
 
StringOnHeapdeepCopy () const
 
const char * cStr () const
 
std::size_t size () const
 
 ~StringOnHeap ()
 

Private Attributes

char * _str
 
std::size_t _len
 
Deallocator _dealloc
 

Friends

class Any
 
class AtomAny
 
class ArrayAny
 

Detailed Description

Definition at line 51 of file Any.hxx.

Constructor & Destructor Documentation

◆ StringOnHeap() [1/4]

StringOnHeap::StringOnHeap ( const char *  val)
private

Definition at line 179 of file Any.cxx.

179  :_str(strdup(val)),_len(strlen(val)),_dealloc(0)
180 {
181 }
std::size_t _len
Definition: Any.hxx:68
Deallocator _dealloc
Definition: Any.hxx:69

Referenced by deepCopy().

◆ StringOnHeap() [2/4]

StringOnHeap::StringOnHeap ( const char *  val,
std::size_t  len 
)
private

Definition at line 183 of file Any.cxx.

183  :_dealloc(0),_len(len)
184 {
185  _str=(char *)malloc(len+1);
186  std::copy(val,val+len,_str);
187  _str[len]='\0';
188 }

References _str.

◆ StringOnHeap() [3/4]

StringOnHeap::StringOnHeap ( const std::string &  val)
private

Definition at line 190 of file Any.cxx.

190  :_dealloc(0),_len(val.size()),_str(nullptr)
191 {
192  _str=(char *)malloc(val.size()+1);
193  std::copy(val.cbegin(),val.cend(),_str);
194  _str[val.size()]='\0';
195 }

References _str.

◆ StringOnHeap() [4/4]

StringOnHeap::StringOnHeap ( char *  val,
Deallocator  deAlloc 
)
private
Note
: no copy is performed if a deallocator is given.
Parameters
val: String in C format that is NOT copied if deAlloc != 0
deAlloc: pointer on function to deallocate val after last use.

Definition at line 204 of file Any.cxx.

204  :_len(0),_dealloc(deAlloc)
205 {
206  if(deAlloc)
207  _str=val;
208  else
209  _str=strdup(val);
210 }

References _str.

◆ ~StringOnHeap()

StringOnHeap::~StringOnHeap ( )
private

Definition at line 225 of file Any.cxx.

226 {
227  if(_dealloc)
228  _dealloc(_str);
229  else
230  free(_str);
231 }

References _dealloc, and _str.

Member Function Documentation

◆ cStr()

const char* YACS::ENGINE::StringOnHeap::cStr ( ) const
inlineprivate

Definition at line 63 of file Any.hxx.

63 { return _str; }

Referenced by YACS::ENGINE::AtomAny::getBytesValue(), and YACS::ENGINE::AtomAny::getStringValue().

◆ deepCopy()

StringOnHeap * StringOnHeap::deepCopy ( ) const
private

Definition at line 217 of file Any.cxx.

218 {
219  if(_len==0)
220  return new StringOnHeap(_str);
221  else
222  return new StringOnHeap(_str,_len);
223 }
StringOnHeap(const char *val)
Definition: Any.cxx:179

References _len, _str, and StringOnHeap().

Referenced by YACS::ENGINE::AtomAny::putMyReprAtPlace().

◆ operator==()

bool StringOnHeap::operator== ( const StringOnHeap other) const
private

Definition at line 212 of file Any.cxx.

213 {
214  return strcmp(_str, other._str)==0;
215 }

References _str.

◆ size()

std::size_t YACS::ENGINE::StringOnHeap::size ( ) const
inlineprivate

Definition at line 64 of file Any.hxx.

64 { return _len; }

Referenced by YACS::ENGINE::AtomAny::getBytesValue(), and YACS::ENGINE::AtomAny::getStringValue().

Friends And Related Function Documentation

◆ Any

friend class Any
friend

Definition at line 53 of file Any.hxx.

◆ ArrayAny

friend class ArrayAny
friend

Definition at line 55 of file Any.hxx.

◆ AtomAny

friend class AtomAny
friend

Definition at line 54 of file Any.hxx.

Member Data Documentation

◆ _dealloc

Deallocator YACS::ENGINE::StringOnHeap::_dealloc
private

Definition at line 69 of file Any.hxx.

Referenced by ~StringOnHeap().

◆ _len

std::size_t YACS::ENGINE::StringOnHeap::_len
private

Definition at line 68 of file Any.hxx.

Referenced by deepCopy().

◆ _str

char* YACS::ENGINE::StringOnHeap::_str
private

Definition at line 67 of file Any.hxx.

Referenced by deepCopy(), operator==(), StringOnHeap(), and ~StringOnHeap().


The documentation for this class was generated from the following files: