Version: 9.15.0
YACS::ENGINE::AtomAny Class Reference

#include <Any.hxx>

Inheritance diagram for YACS::ENGINE::AtomAny:
Collaboration diagram for YACS::ENGINE::AtomAny:

Classes

union  ValueContainer
 

Public Member Functions

Anyclone () const
 
AnyPtr operator[] (int i) const
 
AnyPtr operator[] (const char *key) const
 
bool operator== (const Any &other) const
 
int getIntValue () const
 
bool getBoolValue () const
 
double getDoubleValue () const
 
std::string getStringValue () const
 
const char * getBytesValue (std::size_t &len) const
 
- Public Member Functions inherited from YACS::ENGINE::Any
const TypeCodegetType () const
 
- Public Member Functions inherited from YACS::ENGINE::RefCounter
unsigned int getRefCnt () const
 
void incrRef () const
 
bool decrRef () const
 

Static Public Member Functions

template<class T >
static AtomAnyNew (T val)
 
static AtomAnyNew (char *val, Deallocator dealloc)
 
static AtomAnyNew (const std::string &val, TypeCode *type)
 

Protected Member Functions

void putMyReprAtPlace (char *data) const
 
- Protected Member Functions inherited from YACS::ENGINE::Any
virtual ~Any ()
 
 Any (TypeCode *type)
 
 Any (const Any &other)
 
- Protected Member Functions inherited from YACS::ENGINE::RefCounter
 RefCounter ()
 
 RefCounter (const RefCounter &other)
 
virtual ~RefCounter ()
 

Static Protected Member Functions

static void putReprAtPlace (char *data, const char *src, const TypeCode *type, bool deepCpy)
 
static void destroyReprAtPlace (char *data, const TypeCode *type)
 
static AnyPtr getOrBuildFromData (char *data, const TypeCode *type)
 
static bool takeInChargeStorageOf (TypeCode *type)
 
- Static Protected Member Functions inherited from YACS::ENGINE::Any
static bool IsNull (char *data)
 

Protected Attributes

ValueContainer _value
 
- Protected Attributes inherited from YACS::ENGINE::Any
TypeCode_type
 
- Protected Attributes inherited from YACS::ENGINE::RefCounter
unsigned int _cnt
 

Private Member Functions

 ~AtomAny ()
 
 AtomAny (int val)
 
 AtomAny (bool val)
 
 AtomAny (double val)
 
 AtomAny (const char *val)
 
 AtomAny (const std::string &val)
 
 AtomAny (const std::string &val, TypeCode *type)
 
 AtomAny (const AtomAny &other)
 
 AtomAny (char *data, TypeCode *type)
 
 AtomAny (char *val, Deallocator deAlloc)
 

Friends

class TypeCode
 
class TypeCodeObjref
 

Additional Inherited Members

- Static Public Attributes inherited from YACS::ENGINE::RefCounter
static unsigned int _totalCnt =0
 

Detailed Description

Definition at line 111 of file Any.hxx.

Constructor & Destructor Documentation

◆ ~AtomAny()

AtomAny::~AtomAny ( )
private

◆ AtomAny() [1/9]

AtomAny::AtomAny ( int  val)
private

Definition at line 258 of file Any.cxx.

259 {
260  _value._i=val;
261 }
Any(TypeCode *type)
Definition: Any.cxx:233
static YACS::ENGINE::TypeCode * _tc_int
Definition: Runtime.hxx:137

References YACS::ENGINE::AtomAny::ValueContainer::_i, and _value.

Referenced by clone(), getOrBuildFromData(), and New().

◆ AtomAny() [2/9]

AtomAny::AtomAny ( bool  val)
private

Definition at line 263 of file Any.cxx.

264 {
265  _value._b=val;
266 }
static YACS::ENGINE::TypeCode * _tc_bool
Definition: Runtime.hxx:138

References YACS::ENGINE::AtomAny::ValueContainer::_b, and _value.

◆ AtomAny() [3/9]

AtomAny::AtomAny ( double  val)
private

Definition at line 268 of file Any.cxx.

269 {
270  _value._d=val;
271 }
static YACS::ENGINE::TypeCode * _tc_double
Definition: Runtime.hxx:136

References YACS::ENGINE::AtomAny::ValueContainer::_d, and _value.

◆ AtomAny() [4/9]

AtomAny::AtomAny ( const char *  val)
private

Definition at line 273 of file Any.cxx.

274 {
275  _value._s=new StringOnHeap(val);
276 }
static YACS::ENGINE::TypeCode * _tc_string
Definition: Runtime.hxx:139

References YACS::ENGINE::AtomAny::ValueContainer::_s, and _value.

◆ AtomAny() [5/9]

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

Definition at line 278 of file Any.cxx.

279 {
280  _value._s=new StringOnHeap(val);
281 }

References YACS::ENGINE::AtomAny::ValueContainer::_s, and _value.

◆ AtomAny() [6/9]

AtomAny::AtomAny ( const std::string &  val,
TypeCode type 
)
private

Definition at line 283 of file Any.cxx.

283  :Any(type)
284 {
285  _value._s=new StringOnHeap(val);
286 }

References YACS::ENGINE::AtomAny::ValueContainer::_s, and _value.

◆ AtomAny() [7/9]

◆ AtomAny() [8/9]

◆ AtomAny() [9/9]

AtomAny::AtomAny ( char *  val,
Deallocator  deAlloc 
)
private

Definition at line 303 of file Any.cxx.

304 {
305  _value._s=new StringOnHeap(val,deAlloc);
306 }

References YACS::ENGINE::AtomAny::ValueContainer::_s, and _value.

Member Function Documentation

◆ clone()

Any * AtomAny::clone ( ) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 324 of file Any.cxx.

325 {
326  return new AtomAny(*this);
327 }
AtomAny(int val)
Definition: Any.cxx:258

References AtomAny().

◆ destroyReprAtPlace()

void AtomAny::destroyReprAtPlace ( char *  data,
const TypeCode type 
)
staticprotected
Note
: Opposite method of putMyReprAtPlace. But static because due to data compression instance is lost.

Definition at line 468 of file Any.cxx.

469 {
470  DynType typ=type->kind();
471  if(typ==String || typ==Objref)
472  {
473  if(!Any::IsNull(data))
474  {
475  void **tmp=(void **)data;
476  delete ((StringOnHeap *)(*tmp));
477  }
478  }
479 }
static bool IsNull(char *data)
Definition: Any.cxx:248

References YACS::ENGINE::Any::IsNull(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::Objref, and YACS::ENGINE::String.

Referenced by YACS::ENGINE::TypeCode::destroyZippedAny(), and YACS::ENGINE::TypeCodeObjref::destroyZippedAny().

◆ getBoolValue()

bool AtomAny::getBoolValue ( ) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 374 of file Any.cxx.

375 {
377  return _value._b;
378  else
379  throw Exception("Value is not a bool");
380 }

References YACS::ENGINE::AtomAny::ValueContainer::_b, YACS::ENGINE::Runtime::_tc_bool, YACS::ENGINE::Any::_type, _value, and YACS::ENGINE::TypeCode::isA().

◆ getBytesValue()

const char * AtomAny::getBytesValue ( std::size_t &  len) const

◆ getDoubleValue()

double AtomAny::getDoubleValue ( ) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 382 of file Any.cxx.

383 {
385  return _value._d;
386  else
387  throw Exception("Value is not a double");
388 }

References YACS::ENGINE::AtomAny::ValueContainer::_d, YACS::ENGINE::Runtime::_tc_double, YACS::ENGINE::Any::_type, _value, and YACS::ENGINE::TypeCode::isA().

◆ getIntValue()

int AtomAny::getIntValue ( ) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 366 of file Any.cxx.

367 {
369  return _value._i;
370  else
371  throw Exception("Value is not an int");
372 }

References YACS::ENGINE::AtomAny::ValueContainer::_i, YACS::ENGINE::Runtime::_tc_int, YACS::ENGINE::Any::_type, _value, and YACS::ENGINE::TypeCode::isA().

◆ getOrBuildFromData()

AnyPtr AtomAny::getOrBuildFromData ( char *  data,
const TypeCode type 
)
staticprotected

Definition at line 481 of file Any.cxx.

482 {
483  Any *ret;
484  ret=new AtomAny(data,(TypeCode *)type);
485  return AnyPtr(ret);
486 }
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
Base class for all type objects.
Definition: TypeCode.hxx:68
SharedPtr< Any > AnyPtr
Definition: Any.hxx:72

References AtomAny().

Referenced by YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData(), and YACS::ENGINE::TypeCodeObjref::getOrBuildAnyFromZippedData().

◆ getStringValue()

std::string AtomAny::getStringValue ( ) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 390 of file Any.cxx.

391 {
393  {
394  std::size_t sz(_value._s->size());
395  if(sz==0)
396  return string(_value._s->cStr());
397  else
398  return string(_value._s->cStr(),sz);
399  }
400  else
401  throw Exception("Value is not a string");
402 }

References YACS::ENGINE::AtomAny::ValueContainer::_s, YACS::ENGINE::Runtime::_tc_string, YACS::ENGINE::Any::_type, _value, YACS::ENGINE::StringOnHeap::cStr(), YACS::ENGINE::TypeCode::isA(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::Objref, and YACS::ENGINE::StringOnHeap::size().

◆ New() [1/3]

AtomAny * AtomAny::New ( char *  val,
Deallocator  dealloc 
)
static

Definition at line 329 of file Any.cxx.

330 {
331  return new AtomAny(val,dealloc);
332 }

References AtomAny().

◆ New() [2/3]

AtomAny * AtomAny::New ( const std::string &  val,
TypeCode type 
)
static

Definition at line 334 of file Any.cxx.

335 {
336  return new AtomAny(val,type);
337 }

References AtomAny().

◆ New() [3/3]

◆ operator==()

bool AtomAny::operator== ( const Any other) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 349 of file Any.cxx.

350 {
351  if(!_type->isA(other.getType()))
352  return false;
353  const AtomAny& otherC=(const AtomAny&) other;//cast granted due to previous lines
355  return _value._d==otherC._value._d;
356  else if(_type->isA(Runtime::_tc_int))
357  return _value._i==otherC._value._i;
358  else if(_type->isA(Runtime::_tc_bool))
359  return _value._b==otherC._value._b;
360  else if(_type->isA(Runtime::_tc_string) || _type->kind()==Objref)
361  return (*_value._s)==*(otherC._value._s);
362  else
363  return false;
364 }
const TypeCode * getType() const
Definition: Any.hxx:85

References YACS::ENGINE::AtomAny::ValueContainer::_b, YACS::ENGINE::AtomAny::ValueContainer::_d, YACS::ENGINE::AtomAny::ValueContainer::_i, YACS::ENGINE::AtomAny::ValueContainer::_s, YACS::ENGINE::Runtime::_tc_bool, YACS::ENGINE::Runtime::_tc_double, YACS::ENGINE::Runtime::_tc_int, YACS::ENGINE::Runtime::_tc_string, YACS::ENGINE::Any::_type, _value, YACS::ENGINE::Any::getType(), YACS::ENGINE::TypeCode::isA(), YACS::ENGINE::TypeCode::kind(), and YACS::ENGINE::Objref.

◆ operator[]() [1/2]

AnyPtr AtomAny::operator[] ( const char *  key) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 344 of file Any.cxx.

345 {
346  throw Exception("AtomAny::operator[] : try to get a part of a partitionned data whereas atomical.");
347 }

◆ operator[]() [2/2]

AnyPtr AtomAny::operator[] ( int  i) const
virtual

◆ putMyReprAtPlace()

void AtomAny::putMyReprAtPlace ( char *  data) const
protectedvirtual
Note
: This method put in data its zipped recursive content in data. The ownership of the recursive content is tranfered to data. So this owns nothing and its counter fall by 1. For memory space minimal use, not all of '*this' is pushed at data location.
Parameters
data: already allocated memory zone where to put compressed content of 'this'

Implements YACS::ENGINE::Any.

Definition at line 422 of file Any.cxx.

423 {
425  {
426  StringOnHeap *tmp=_value._s->deepCopy();
427  memcpy(data,&tmp,_type->getSizeInByteOfAnyReprInSeq());
428  }
429  else if(_type->isA(Runtime::_tc_double))
430  memcpy(data,&_value._d,_type->getSizeInByteOfAnyReprInSeq());
431  else if(_type->isA(Runtime::_tc_int))
432  memcpy(data,&_value._i,_type->getSizeInByteOfAnyReprInSeq());
433  else if(_type->isA(Runtime::_tc_bool))
434  memcpy(data,&_value._b,_type->getSizeInByteOfAnyReprInSeq());
435 }
StringOnHeap * deepCopy() const
Definition: Any.cxx:217

References YACS::ENGINE::AtomAny::ValueContainer::_b, YACS::ENGINE::AtomAny::ValueContainer::_d, YACS::ENGINE::AtomAny::ValueContainer::_i, YACS::ENGINE::AtomAny::ValueContainer::_s, YACS::ENGINE::Runtime::_tc_bool, YACS::ENGINE::Runtime::_tc_double, YACS::ENGINE::Runtime::_tc_int, YACS::ENGINE::Runtime::_tc_string, YACS::ENGINE::Any::_type, _value, YACS::ENGINE::StringOnHeap::deepCopy(), YACS::ENGINE::TypeCode::getSizeInByteOfAnyReprInSeq(), YACS::ENGINE::TypeCode::isA(), YACS::ENGINE::TypeCode::kind(), and YACS::ENGINE::Objref.

◆ putReprAtPlace()

void AtomAny::putReprAtPlace ( char *  data,
const char *  src,
const TypeCode type,
bool  deepCpy 
)
staticprotected
Note
: This method put in data its zipped recursive content in data. The ownership of the recursive content is tranfered to data. So this owns nothing and its counter fall by 1. For memory space minimal use, not all of '*this' is pushed at data location. 'deepCpy' param is not used here because by definition of AtomAny deep copy is performed.
Parameters
data: already allocated memory zone where to put compressed content of 'this'
src:
type:
deepCpy:

Definition at line 448 of file Any.cxx.

449 {
450  if(type->isA(Runtime::_tc_string) || type->kind()==YACS::ENGINE::Objref)
451  {
452  void **tmp1=(void **)src;
453  StringOnHeap *tmp=((const StringOnHeap *)(*tmp1))->deepCopy();
454  memcpy(data,&tmp,type->getSizeInByteOfAnyReprInSeq());
455  }
456  else if(type->isA(Runtime::_tc_double))
457  memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
458  else if(type->isA(Runtime::_tc_int))
459  memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
460  else if(type->isA(Runtime::_tc_bool))
461  memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
462 }

References YACS::ENGINE::Runtime::_tc_bool, YACS::ENGINE::Runtime::_tc_double, YACS::ENGINE::Runtime::_tc_int, YACS::ENGINE::Runtime::_tc_string, YACS::ENGINE::TypeCode::getSizeInByteOfAnyReprInSeq(), YACS::ENGINE::TypeCode::isA(), YACS::ENGINE::TypeCode::kind(), and YACS::ENGINE::Objref.

Referenced by YACS::ENGINE::TypeCode::putReprAtPlace(), and YACS::ENGINE::TypeCodeObjref::putReprAtPlace().

◆ takeInChargeStorageOf()

bool AtomAny::takeInChargeStorageOf ( TypeCode type)
staticprotected

Definition at line 488 of file Any.cxx.

489 {
490  DynType typ=type->kind();
491  return (typ==Double || typ==Int || typ==Bool || typ==String);
492 }

References YACS::ENGINE::Bool, YACS::ENGINE::Double, YACS::ENGINE::Int, YACS::ENGINE::TypeCode::kind(), and YACS::ENGINE::String.

Friends And Related Function Documentation

◆ TypeCode

friend class TypeCode
friend

Definition at line 113 of file Any.hxx.

◆ TypeCodeObjref

friend class TypeCodeObjref
friend

Definition at line 114 of file Any.hxx.

Member Data Documentation

◆ _value

ValueContainer YACS::ENGINE::AtomAny::_value
protected

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