Version: 9.15.0
YACS::ENGINE::TypeCodeStruct Class Reference

Class for struct type. More...

#include <TypeCode.hxx>

Inheritance diagram for YACS::ENGINE::TypeCodeStruct:
Collaboration diagram for YACS::ENGINE::TypeCodeStruct:

Public Member Functions

 TypeCodeStruct (const char *repositoryId, const char *name)
 Create a struct type with a given name and a given id. More...
 
TypeCodeclone () const
 
void putReprAtPlace (char *pt, const char *val, bool deepCpy) const
 
void destroyZippedAny (char *data) const
 
AnyPtr getOrBuildAnyFromZippedData (char *data) const
 
const char * id () const
 
const char * name () const
 
const char * shortName () const
 
virtual unsigned getSizeInByteOfAnyReprInSeq () const
 
const TypeCodecontentType () const
 
virtual int isA (const char *repositoryId) const
 Check if this TypeCode is derived from a TypeCode with a given id. More...
 
virtual int isA (const TypeCode *tc) const
 Check if this TypeCode is derived from a given TypeCode. More...
 
virtual int isAdaptable (const TypeCode *tc) const
 Check if this TypeCode is adaptable to a given TypeCode (tc) More...
 
virtual int isEquivalent (const TypeCode *tc) const
 Check if this TypeCode can be used in place of tc. More...
 
virtual void addMember (const std::string &name, TypeCode *tc)
 The only non const method. More...
 
const TypeCodegetMember (const std::string &name, unsigned &offset) const
 Get typecode of struct member given its name. More...
 
int memberCount () const
 
const char * memberName (int index) const
 
TypeCodememberType (int index) const
 
- Public Member Functions inherited from YACS::ENGINE::TypeCode
 TypeCode (DynType kind)
 
DynType kind () const
 
const char * getKindRepr () const
 
const TypeCodesubContentType (int lev) const
 
virtual std::string getPrintStr () const
 
- Public Member Functions inherited from YACS::ENGINE::RefCounter
unsigned int getRefCnt () const
 
void incrRef () const
 
bool decrRef () const
 

Protected Member Functions

virtual ~TypeCodeStruct ()
 
 TypeCodeStruct (const TypeCodeStruct &tc)
 
- Protected Member Functions inherited from YACS::ENGINE::TypeCodeComposed
 TypeCodeComposed (const TypeCodeComposed &other)
 
 TypeCodeComposed (DynType kind, const char *repositoryId, const char *name)
 
- Protected Member Functions inherited from YACS::ENGINE::TypeCode
 TypeCode (const TypeCode &tc)
 
TypeCodeoperator= (const TypeCode &tc)
 
virtual ~TypeCode ()
 
- Protected Member Functions inherited from YACS::ENGINE::RefCounter
 RefCounter ()
 
 RefCounter (const RefCounter &other)
 
virtual ~RefCounter ()
 

Private Attributes

std::vector< std::pair< std::string, TypeCode * > > _members
 

Friends

class StructAny
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::ENGINE::TypeCode
static const char * getKindRepr (DynType kind)
 
static TypeCodeinterfaceTc (const char *id, const char *name)
 static factory of object reference type given an id and a name More...
 
static TypeCodeinterfaceTc (const char *id, const char *name, const std::list< TypeCodeObjref * > &ltc)
 static factory of object reference type given an id, a name and a list of base types More...
 
static TypeCodesequenceTc (const char *id, const char *name, TypeCode *content)
 static factory of sequence type given an id, a name and a content type More...
 
static TypeCodestructTc (const char *id, const char *name)
 static factory of struct type given an id and a name More...
 
- Static Public Attributes inherited from YACS::ENGINE::RefCounter
static unsigned int _totalCnt =0
 
- Protected Attributes inherited from YACS::ENGINE::TypeCodeComposed
const std::string _name
 
const std::string _repoId
 
std::string _shortName
 
- Protected Attributes inherited from YACS::ENGINE::TypeCode
const DynType _kind
 
- Protected Attributes inherited from YACS::ENGINE::RefCounter
unsigned int _cnt
 
- Static Protected Attributes inherited from YACS::ENGINE::TypeCode
static const char * KIND_STR_REPR [] ={ "None", "double", "int", "string", "bool", "Objref", "Sequence", "Array","Struct" }
 

Detailed Description

Class for struct type.

Definition at line 227 of file TypeCode.hxx.

Constructor & Destructor Documentation

◆ TypeCodeStruct() [1/2]

TypeCodeStruct::TypeCodeStruct ( const char *  repositoryId,
const char *  name 
)

Create a struct type with a given name and a given id.

Parameters
repositoryId: the given id
name: the given name

Definition at line 644 of file TypeCode.cxx.

645  : TypeCodeComposed(Struct,repositoryId,name)
646 {
647 }
TypeCodeComposed(const TypeCodeComposed &other)
Definition: TypeCode.cxx:275
const char * name() const
Definition: TypeCode.cxx:686

Referenced by clone().

◆ ~TypeCodeStruct()

TypeCodeStruct::~TypeCodeStruct ( )
protectedvirtual

Definition at line 649 of file TypeCode.cxx.

650 {
651  for(vector< pair<string,TypeCode*> >::iterator iter=_members.begin();iter!=_members.end();iter++)
652  (*iter).second->decrRef();
653 }
std::vector< std::pair< std::string, TypeCode * > > _members
Definition: TypeCode.hxx:257

References _members.

◆ TypeCodeStruct() [2/2]

TypeCodeStruct::TypeCodeStruct ( const TypeCodeStruct tc)
protected

Definition at line 660 of file TypeCode.cxx.

661 {
662  for(vector< std::pair<std::string,TypeCode*> >::iterator iter=_members.begin();iter!=_members.end();iter++)
663  (*iter).second->incrRef();
664 }

References _members, and YACS::ENGINE::RefCounter::incrRef().

Member Function Documentation

◆ addMember()

void TypeCodeStruct::addMember ( const std::string &  name,
TypeCode tc 
)
virtual

The only non const method.

Definition at line 781 of file TypeCode.cxx.

782 {
783  DEBTRACE(name << " " << tc->name());
784  std::vector< std::pair<std::string,TypeCode*> >::const_iterator iter;
785  for(iter=_members.begin();iter != _members.end(); iter++)
786  {
787  if((*iter).first == name)
788  throw Exception("Struct member " + name + " already defined");
789  }
790  _members.push_back(std::pair<std::string,TypeCode*>(name,tc));
791  tc->incrRef();
792 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual const char * name() const
Definition: TypeCode.cxx:72

References _members, DEBTRACE, YACS::ENGINE::RefCounter::incrRef(), YACS::ENGINE::TypeCode::name(), and name().

Referenced by YACS::ENGINE::Runtime::Runtime().

◆ clone()

TypeCode * TypeCodeStruct::clone ( ) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 655 of file TypeCode.cxx.

656 {
657  return new TypeCodeStruct(*this);
658 }
TypeCodeStruct(const char *repositoryId, const char *name)
Create a struct type with a given name and a given id.
Definition: TypeCode.cxx:644

References TypeCodeStruct().

◆ contentType()

const TypeCode * TypeCodeStruct::contentType ( ) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 704 of file TypeCode.cxx.

705 {
706  const char what[]="Content type is specified by giving a key.";
707  throw Exception(what);
708 }

◆ destroyZippedAny()

void TypeCodeStruct::destroyZippedAny ( char *  data) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 671 of file TypeCode.cxx.

672 {
674 }
static void destroyReprAtPlace(char *data, const TypeCodeStruct *type)
Definition: Any.cxx:1138

References YACS::ENGINE::StructAny::destroyReprAtPlace().

◆ getMember()

const TypeCode * TypeCodeStruct::getMember ( const std::string &  name,
unsigned &  offset 
) const

Get typecode of struct member given its name.

If name is not an existing key, 0 is returned.

Parameters
name: the member name
offset: Out parameter, that specified the location of start of data discriminated by name key.
Returns
the member TypeCode

Definition at line 801 of file TypeCode.cxx.

802 {
803  std::vector< std::pair<std::string,TypeCode*> >::const_iterator iter;
804  offset=0;
805  for(iter=_members.begin();iter != _members.end(); iter++)
806  {
807  if((*iter).first==name)
808  return (*iter).second;
809  offset+=(*iter).second->getSizeInByteOfAnyReprInSeq();
810  }
811  return 0;
812 }

References _members, YACS::ENGINE::TypeCode::getSizeInByteOfAnyReprInSeq(), and name().

Referenced by YACS::ENGINE::StructAny::setEltAtRank().

◆ getOrBuildAnyFromZippedData()

AnyPtr TypeCodeStruct::getOrBuildAnyFromZippedData ( char *  data) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 676 of file TypeCode.cxx.

677 {
678  return StructAny::getOrBuildFromData(data,this);
679 }
static AnyPtr getOrBuildFromData(char *data, const TypeCodeStruct *type)
Definition: Any.cxx:1149

References YACS::ENGINE::StructAny::getOrBuildFromData().

◆ getSizeInByteOfAnyReprInSeq()

unsigned TypeCodeStruct::getSizeInByteOfAnyReprInSeq ( ) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 696 of file TypeCode.cxx.

697 {
698  unsigned ret=0;
699  for(vector< pair<string,TypeCode*> >::const_iterator iter=_members.begin();iter!=_members.end();iter++)
700  ret+=(*iter).second->getSizeInByteOfAnyReprInSeq();
701  return ret;
702 }

References _members.

◆ id()

const char * TypeCodeStruct::id ( ) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 681 of file TypeCode.cxx.

682 {
683  return _repoId.c_str();
684 };
const std::string _repoId
Definition: TypeCode.hxx:115

References YACS::ENGINE::TypeCodeComposed::_repoId.

◆ isA() [1/2]

int TypeCodeStruct::isA ( const char *  id) const
virtual

Check if this TypeCode is derived from a TypeCode with a given id.

Parameters
id: a given id
Returns
1 if true, 0 if false

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 715 of file TypeCode.cxx.

716 {
717  if(_repoId == id)return 1;
718  return 0;
719 }

References YACS::ENGINE::TypeCodeComposed::_repoId.

Referenced by isA().

◆ isA() [2/2]

int TypeCodeStruct::isA ( const TypeCode tc) const
virtual

Check if this TypeCode is derived from a given TypeCode.

Parameters
tc: the given TypeCode
Returns
1 if true, 0 if false

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 726 of file TypeCode.cxx.

727 {
728  if(_kind != tc->kind()) return 0;
729  if(_repoId == tc->id())return 1;
730  int nMember=memberCount();
731  if(nMember != ((TypeCodeStruct*)tc)->memberCount())return 0;
732  for(int i=0;i<nMember;i++)
733  {
734  const char * name=memberName(i);
735  if(strcmp(memberName(i),((TypeCodeStruct*)tc)->memberName(i)) != 0)return 0;
736  if(!memberType(i)->isA(((TypeCodeStruct*)tc)->memberType(i)))return 0;
737  }
738  return 1;
739 }
Class for struct type.
Definition: TypeCode.hxx:228
const char * memberName(int index) const
Definition: TypeCode.cxx:819
TypeCode * memberType(int index) const
Definition: TypeCode.cxx:831
virtual int isA(const char *repositoryId) const
Check if this TypeCode is derived from a TypeCode with a given id.
Definition: TypeCode.cxx:715
virtual const char * id() const
Definition: TypeCode.cxx:82
DynType kind() const
Definition: TypeCode.cxx:47
const DynType _kind
Definition: TypeCode.hxx:104

References YACS::ENGINE::TypeCode::_kind, YACS::ENGINE::TypeCodeComposed::_repoId, yacsorb.CORBAEngineTest::i, YACS::ENGINE::TypeCode::id(), isA(), YACS::ENGINE::TypeCode::kind(), memberCount(), memberName(), memberType(), and name().

◆ isAdaptable()

int TypeCodeStruct::isAdaptable ( const TypeCode tc) const
virtual

Check if this TypeCode is adaptable to a given TypeCode (tc)

Parameters
tc: the given TypeCode
Returns
1 if true, 0 if false

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 746 of file TypeCode.cxx.

747 {
748  if (_kind != tc->kind()) return 0;
749  if (_repoId == tc->id()) return 1;
750  int nMember = memberCount();
751  if (nMember != ((TypeCodeStruct*)tc)->memberCount()) return 0;
752  for (int i=0 ; i<nMember ; i++)
753  {
754  const char * name = memberName(i);
755  if (strcmp(memberName(i), ((TypeCodeStruct*)tc)->memberName(i)) != 0) return 0;
756  if (!memberType(i)->isAdaptable(((TypeCodeStruct*)tc)->memberType(i))) return 0;
757  }
758  return 1;
759 }
virtual int isAdaptable(const TypeCode *tc) const
Check if this TypeCode is adaptable to a given TypeCode (tc)
Definition: TypeCode.cxx:746

References YACS::ENGINE::TypeCode::_kind, YACS::ENGINE::TypeCodeComposed::_repoId, yacsorb.CORBAEngineTest::i, YACS::ENGINE::TypeCode::id(), YACS::ENGINE::TypeCode::kind(), memberCount(), memberName(), memberType(), and name().

◆ isEquivalent()

int TypeCodeStruct::isEquivalent ( const TypeCode tc) const
virtual

Check if this TypeCode can be used in place of tc.

this TypeCode is equivalent to tc if they have the same kind

Parameters
tc: the TypeCode to compare

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 767 of file TypeCode.cxx.

768 {
769  if(_kind != tc->kind()) return 0;
770  int nMember=memberCount();
771  if(nMember != ((TypeCodeStruct*)tc)->memberCount())return 0;
772  for(int i=0;i<nMember;i++)
773  {
774  const char * name=memberName(i);
775  if(strcmp(memberName(i),((TypeCodeStruct*)tc)->memberName(i)) != 0)return 0;
776  if(!memberType(i)->isEquivalent(((TypeCodeStruct*)tc)->memberType(i)))return 0;
777  }
778  return 1;
779 }
virtual int isEquivalent(const TypeCode *tc) const
Check if this TypeCode can be used in place of tc.
Definition: TypeCode.cxx:767

References YACS::ENGINE::TypeCode::_kind, yacsorb.CORBAEngineTest::i, YACS::ENGINE::TypeCode::kind(), memberCount(), memberName(), memberType(), and name().

◆ memberCount()

◆ memberName()

◆ memberType()

◆ name()

const char * TypeCodeStruct::name ( ) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 686 of file TypeCode.cxx.

687 {
688  return _name.c_str();
689 }

References YACS::ENGINE::TypeCodeComposed::_name.

Referenced by addMember(), getMember(), isA(), isAdaptable(), and isEquivalent().

◆ putReprAtPlace()

void TypeCodeStruct::putReprAtPlace ( char *  pt,
const char *  val,
bool  deepCpy 
) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 666 of file TypeCode.cxx.

667 {
668  StructAny::putReprAtPlace(pt,val,this,deepCpy);
669 }
static void putReprAtPlace(char *data, const char *src, const TypeCodeStruct *type, bool deepCpy)
Definition: Any.cxx:1127

References YACS::ENGINE::StructAny::putReprAtPlace().

◆ shortName()

const char * TypeCodeStruct::shortName ( ) const
virtual

Reimplemented from YACS::ENGINE::TypeCode.

Definition at line 691 of file TypeCode.cxx.

692 {
693  return _shortName.c_str();
694 }

References YACS::ENGINE::TypeCodeComposed::_shortName.

Friends And Related Function Documentation

◆ StructAny

friend class StructAny
friend

Definition at line 229 of file TypeCode.hxx.

Member Data Documentation

◆ _members


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