Version: 8.3.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 throw (Exception)
 
AnyPtr operator[] (const char *key) const throw (Exception)
 
bool operator== (const Any &other) const
 
int getIntValue () const throw (Exception)
 
bool getBoolValue () const throw (Exception)
 
double getDoubleValue () const throw (Exception)
 
std::string getStringValue () const throw (Exception)
 
- 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 ()
 

Static Public Member Functions

template<class T >
static AtomAnyNew (T val)
 
static AtomAnyNew (char *val, Deallocator dealloc)
 

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 AtomAny &other)
 
 AtomAny (char *data, TypeCode *type)
 
 AtomAny (char *val, Deallocator deAlloc)
 

Friends

class TypeCode
 

Additional Inherited Members

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

Detailed Description

Definition at line 102 of file Any.hxx.

Constructor & Destructor Documentation

AtomAny::~AtomAny ( )
private

Definition at line 309 of file Any.cxx.

References YACS::ENGINE::AtomAny::ValueContainer::_s, YACS::ENGINE::Any::_type, _value, YACS::ENGINE::TypeCode::kind(), and YACS::ENGINE::String.

310 {
311  if(_type->kind() == String)
312  delete _value._s;
313 }
AtomAny::AtomAny ( int  val)
private

Definition at line 100 of file Any.cxx.

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

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

101 {
102  _value._i=val;
103 }
AtomAny::AtomAny ( bool  val)
private

Definition at line 105 of file Any.cxx.

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

106 {
107  _value._b=val;
108 }
AtomAny::AtomAny ( double  val)
private

Definition at line 110 of file Any.cxx.

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

111 {
112  _value._d=val;
113 }
AtomAny::AtomAny ( const char *  val)
private

Definition at line 115 of file Any.cxx.

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

116 {
117  _value._s=new StringOnHeap(val);
118 }
AtomAny::AtomAny ( const std::string &  val)
private

Definition at line 120 of file Any.cxx.

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

121 {
122  _value._s=new StringOnHeap(val);
123 }
AtomAny::AtomAny ( char *  data,
TypeCode type 
)
private
AtomAny::AtomAny ( char *  val,
Deallocator  deAlloc 
)
private

Definition at line 140 of file Any.cxx.

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

141 {
142  _value._s=new StringOnHeap(val,deAlloc);
143 }

Member Function Documentation

Any * AtomAny::clone ( ) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 161 of file Any.cxx.

References AtomAny().

162 {
163  return new AtomAny(*this);
164 }
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 283 of file Any.cxx.

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

Referenced by YACS::ENGINE::TypeCode::destroyZippedAny().

284 {
285  DynType typ=type->kind();
286  if(typ==String)
287  {
288  if(!Any::IsNull(data))
289  {
290  void **tmp=(void **)data;
291  delete ((StringOnHeap *)(*tmp));
292  }
293  }
294 }
bool AtomAny::getBoolValue ( ) const throw (Exception)
virtual

Implements YACS::ENGINE::Any.

Definition at line 206 of file Any.cxx.

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

207 {
209  return _value._b;
210  else
211  throw Exception("Value is not a bool");
212 }
double AtomAny::getDoubleValue ( ) const throw (Exception)
virtual

Implements YACS::ENGINE::Any.

Definition at line 214 of file Any.cxx.

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

215 {
217  return _value._d;
218  else
219  throw Exception("Value is not a double");
220 }
int AtomAny::getIntValue ( ) const throw (Exception)
virtual

Implements YACS::ENGINE::Any.

Definition at line 198 of file Any.cxx.

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

199 {
201  return _value._i;
202  else
203  throw Exception("Value is not an int");
204 }
AnyPtr AtomAny::getOrBuildFromData ( char *  data,
const TypeCode type 
)
staticprotected

Definition at line 296 of file Any.cxx.

References AtomAny(), and PMMLBasicsTestLauncher::ret.

Referenced by YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData().

297 {
298  Any *ret;
299  ret=new AtomAny(data,(TypeCode *)type);
300  return AnyPtr(ret);
301 }
std::string AtomAny::getStringValue ( ) const throw (Exception)
virtual

Implements YACS::ENGINE::Any.

Definition at line 222 of file Any.cxx.

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

223 {
225  return string(_value._s->cStr());
226  else
227  throw Exception("Value is not a string");
228 }
AtomAny * AtomAny::New ( char *  val,
Deallocator  dealloc 
)
static

Definition at line 166 of file Any.cxx.

References AtomAny().

167 {
168  return new AtomAny(val,dealloc);
169 }
bool AtomAny::operator== ( const Any other) const
virtual

Implements YACS::ENGINE::Any.

Definition at line 181 of file Any.cxx.

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(), and YACS::ENGINE::TypeCode::isA().

182 {
183  if(!_type->isA(other.getType()))
184  return false;
185  const AtomAny& otherC=(const AtomAny&) other;//cast granted due to previous lines
187  return _value._d==otherC._value._d;
188  else if(_type->isA(Runtime::_tc_int))
189  return _value._i==otherC._value._i;
190  else if(_type->isA(Runtime::_tc_bool))
191  return _value._b==otherC._value._b;
192  else if(_type->isA(Runtime::_tc_string))
193  return (*_value._s)==*(otherC._value._s);
194  else
195  return false;
196 }
AnyPtr AtomAny::operator[] ( int  i) const throw (Exception)
virtual

Implements YACS::ENGINE::Any.

Definition at line 171 of file Any.cxx.

References YACS::ENGINE::Sequence.

172 {
174 }
AnyPtr AtomAny::operator[] ( const char *  key) const throw (Exception)
virtual

Implements YACS::ENGINE::Any.

Definition at line 176 of file Any.cxx.

177 {
178  throw Exception("AtomAny::operator[] : try to get a part of a partitionned data whereas atomical.");
179 }
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 237 of file Any.cxx.

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(), and YACS::ENGINE::TypeCode::isA().

238 {
240  {
241  StringOnHeap *tmp=_value._s->deepCopy();
242  memcpy(data,&tmp,_type->getSizeInByteOfAnyReprInSeq());
243  }
244  else if(_type->isA(Runtime::_tc_double))
245  memcpy(data,&_value._d,_type->getSizeInByteOfAnyReprInSeq());
246  else if(_type->isA(Runtime::_tc_int))
247  memcpy(data,&_value._i,_type->getSizeInByteOfAnyReprInSeq());
248  else if(_type->isA(Runtime::_tc_bool))
249  memcpy(data,&_value._b,_type->getSizeInByteOfAnyReprInSeq());
250 }
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 263 of file Any.cxx.

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(), and YACS::ENGINE::TypeCode::isA().

Referenced by YACS::ENGINE::TypeCode::putReprAtPlace().

264 {
265  if(type->isA(Runtime::_tc_string))
266  {
267  void **tmp1=(void **)src;
268  StringOnHeap *tmp=((const StringOnHeap *)(*tmp1))->deepCopy();
269  memcpy(data,&tmp,type->getSizeInByteOfAnyReprInSeq());
270  }
271  else if(type->isA(Runtime::_tc_double))
272  memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
273  else if(type->isA(Runtime::_tc_int))
274  memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
275  else if(type->isA(Runtime::_tc_bool))
276  memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
277 }
bool AtomAny::takeInChargeStorageOf ( TypeCode type)
staticprotected

Definition at line 303 of file Any.cxx.

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

304 {
305  DynType typ=type->kind();
306  return (typ==Double || typ==Int || typ==Bool || typ==String);
307 }

Friends And Related Function Documentation

friend class TypeCode
friend

Definition at line 104 of file Any.hxx.

Member Data Documentation

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

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