Develop Biology
The language of life
bio::chemical::PeriodicTableImplementation Class Reference

#include <PeriodicTable.h>

+ Inheritance diagram for bio::chemical::PeriodicTableImplementation:
+ Collaboration diagram for bio::chemical::PeriodicTableImplementation:

Public Member Functions

 PeriodicTableImplementation ()
 
virtual ~PeriodicTableImplementation ()
 
virtual bool AssociateType (AtomicNumber id, physical::Wave *type)
 
virtual bool DisassociateType (AtomicNumber id)
 
template<typename T >
AtomicNumber GetIdFromType ()
 
template<typename T >
AtomicNumber GetIdFromType (const T t)
 
template<typename T >
Name GetNameFromType () const
 
template<typename T >
Name GetNameFromType (const T t) const
 
template<typename T >
const Properties GetPropertiesOf () const
 
const Properties GetPropertiesOf (AtomicNumber id) const
 
const Properties GetPropertiesOf (Name name) const
 
virtual const physical::WaveGetTypeFromId (AtomicNumber id) const
 
AtomicNumber RecordPropertiesOf (AtomicNumber id, Properties properties)
 
AtomicNumber RecordPropertiesOf (Name name, Properties properties)
 
template<typename T >
AtomicNumber RecordPropertiesOf (Properties properties)
 
AtomicNumber RecordPropertyOf (AtomicNumber id, Property property)
 
AtomicNumber RecordPropertyOf (Name name, Property property)
 
template<typename T >
AtomicNumber RecordPropertyOf (Property property)
 
- Public Member Functions inherited from bio::physical::Perspective< AtomicNumber >
 Perspective ()
 
virtual ~Perspective ()
 
virtual bool AssociateType (Id id, Wave *type)
 
virtual bool DisassociateType (Id id)
 
Hadits::iterator Find (Id id)
 
Hadits::const_iterator Find (Id id) const
 
virtual Id GetIdFromName (Name name)
 
virtual Id GetIdWithoutCreation (Name name) const
 
virtual Name GetNameFromId (Id id) const
 
virtual WaveGetNewObjectFromId (Id id) const
 
GetNewObjectFromIdAs (Id id)
 
virtual WaveGetNewObjectFromName (Name name)
 
GetNewObjectFromNameAs (Name name)
 
virtual Id GetNumUsedIds () const
 
virtual const WaveGetTypeFromId (Id id) const
 
const T GetTypeFromIdAs (Id id) const
 
virtual const WaveGetTypeFromName (Name name) const
 
const T GetTypeFromNameAs (Name name) const
 
virtual Id GetUniqueIdFor (Name name)
 
- Public Member Functions inherited from bio::ThreadSafe
 ThreadSafe ()
 
 ThreadSafe (const ThreadSafe &toCopy)
 
virtual ~ThreadSafe ()
 
void LockThread () const
 
void UnlockThread () const
 

Additional Inherited Members

- Public Types inherited from bio::physical::Perspective< AtomicNumber >
typedef std::vector< Hadit > Hadits
 
typedef AtomicNumber Id
 
typedef std::vector< IdIds
 
- Static Public Member Functions inherited from bio::physical::Perspective< AtomicNumber >
static Id InvalidId ()
 
static Name InvalidName ()
 
- Protected Attributes inherited from bio::physical::Perspective< AtomicNumber >
Hadits m_hadits
 
Id m_nextId
 

Detailed Description

The PeriodicTable is a stand-in for runtime type information (RTTI). Instead of having to rely on code compiled with RTTI enabled, we implement our own type tracking mechanism.

The PeriodicTable tracks Properties of types in addition to assigning them an AtomicNumber.. This is done because neither static nor virtual methods will allow for the inverted inheritance necessary to make inverted-inheritance methods like Atom::CallForAll work properly. See Elementary.h for a more detailed description of this system.

Definition at line 40 of file PeriodicTable.h.

Constructor & Destructor Documentation

◆ PeriodicTableImplementation()

bio::chemical::PeriodicTableImplementation::PeriodicTableImplementation ( )

Definition at line 55 of file PeriodicTable.cpp.

56{
57
58}

◆ ~PeriodicTableImplementation()

bio::chemical::PeriodicTableImplementation::~PeriodicTableImplementation ( )
virtual

Definition at line 60 of file PeriodicTable.cpp.

61{
62
63}

Member Function Documentation

◆ AssociateType()

bool bio::chemical::PeriodicTableImplementation::AssociateType ( AtomicNumber  id,
physical::Wave type 
)
virtual

Associates the given Wave type with the given id. This is only necessary if you want to use GetTypeFromId later on. Associating a type with an id has no effect on the Recorded Properties.

Parameters
id
type
Returns
true if the association completed successfully else false

Definition at line 146 of file PeriodicTable.cpp.

150{
151 Element* element = ForceCast< Element* >(Perspective::GetTypeFromId(id));
152 BIO_SANITIZE(element, ,
153 return false);
154 LockThread();
155 element->m_type = type;
156 UnlockThread();
157 return true;
158}
#define BIO_SANITIZE(test, success, failure)
void LockThread() const
Definition: ThreadSafe.cpp:84
void UnlockThread() const
Definition: ThreadSafe.cpp:97

References BIO_SANITIZE, bio::ThreadSafe::LockThread(), bio::chemical::Element::m_type, and bio::ThreadSafe::UnlockThread().

◆ DisassociateType()

bool bio::chemical::PeriodicTableImplementation::DisassociateType ( AtomicNumber  id)
virtual

Removes the type association created by AssociateType(). Disassociating a type has no effect on the Recorded Properties.

Parameters
id
Returns
true if the association was removed else false.

Definition at line 160 of file PeriodicTable.cpp.

161{
162 Element* element = ForceCast< Element* >(Perspective::GetTypeFromId(id));
163 BIO_SANITIZE(element, ,
164 return false);
165 LockThread();
166 element->m_type = NULL;
167 UnlockThread();
168 return true;
169}

References BIO_SANITIZE, bio::ThreadSafe::LockThread(), bio::chemical::Element::m_type, and bio::ThreadSafe::UnlockThread().

◆ GetIdFromType() [1/2]

template<typename T >
AtomicNumber bio::chemical::PeriodicTableImplementation::GetIdFromType ( )
inline
Template Parameters
T
Returns
the AtomicNumber associated with the given type.

Definition at line 81 of file PeriodicTable.h.

82 {
83 return GetIdFromName(GetNameFromType< T >());
84 }

References bio::physical::Perspective< AtomicNumber >::GetIdFromName().

◆ GetIdFromType() [2/2]

template<typename T >
AtomicNumber bio::chemical::PeriodicTableImplementation::GetIdFromType ( const T  t)
inline

For auto template determination.

Template Parameters
T
Parameters
t
Returns
the AtomicNumber associated with the given type.

Definition at line 93 of file PeriodicTable.h.

94 {
95 return GetIdFromType< T >();
96 }

◆ GetNameFromType() [1/2]

template<typename T >
Name bio::chemical::PeriodicTableImplementation::GetNameFromType ( ) const
inline
Template Parameters
T
Returns
the Name associated with the given type.

Definition at line 59 of file PeriodicTable.h.

60 {
61 return TypeName< T >().c_str();
62 }

◆ GetNameFromType() [2/2]

template<typename T >
Name bio::chemical::PeriodicTableImplementation::GetNameFromType ( const T  t) const
inline

For auto template determination.

Template Parameters
T
Parameters
t
Returns
the Name associated with the given type.

Definition at line 71 of file PeriodicTable.h.

72 {
73 return GetNameFromType< T >();
74 }

◆ GetPropertiesOf() [1/3]

template<typename T >
const Properties bio::chemical::PeriodicTableImplementation::GetPropertiesOf ( ) const
inline
Template Parameters
T
Returns
whatever properties have been Recorded for the given type.

Definition at line 115 of file PeriodicTable.h.

116 {
117 return GetPropertiesOf(TypeName< T >().c_str());
118 }
const Properties GetPropertiesOf() const

References GetPropertiesOf().

Referenced by GetPropertiesOf().

◆ GetPropertiesOf() [2/3]

const Properties bio::chemical::PeriodicTableImplementation::GetPropertiesOf ( AtomicNumber  id) const
Parameters
id
Returns
whatever properties have been Recorded for the given type.

Definition at line 65 of file PeriodicTable.cpp.

66{
67 Properties ret;
68 Element* element = ForceCast< Element* >(Perspective::GetTypeFromId(id));
69 BIO_SANITIZE(element, ,
70 return ret);
71 LockThread();
72 ret = element->GetAllAsVector< Property >();
74 return ret;
75}
uint8_t Properties
Definition: Types.h:58

References BIO_SANITIZE, bio::chemical::UnorderedStructureInterface::GetAllAsVector(), bio::ThreadSafe::LockThread(), bio::Properties, and bio::ThreadSafe::UnlockThread().

◆ GetPropertiesOf() [3/3]

const Properties bio::chemical::PeriodicTableImplementation::GetPropertiesOf ( Name  name) const
Parameters
name
Returns
whatever properties have been Recorded for the given type.

Definition at line 77 of file PeriodicTable.cpp.

78{
80}
virtual Id GetIdWithoutCreation(Name name) const
Definition: Perspective.h:310

References bio::physical::Perspective< AtomicNumber >::GetIdWithoutCreation(), and GetPropertiesOf().

◆ GetTypeFromId()

const physical::Wave * bio::chemical::PeriodicTableImplementation::GetTypeFromId ( AtomicNumber  id) const
virtual

Only works if AssociateType has been called with the given id.

Parameters
id
Returns
the pointer to the Wave type associated with the given id else NULL.

Definition at line 138 of file PeriodicTable.cpp.

139{
140 Element* element = ForceCast< Element* >(Perspective::GetTypeFromId(id));
141 BIO_SANITIZE(element, ,
142 return NULL);
143 return element->m_type;
144}

References BIO_SANITIZE, and bio::chemical::Element::m_type.

◆ RecordPropertiesOf() [1/3]

AtomicNumber bio::chemical::PeriodicTableImplementation::RecordPropertiesOf ( AtomicNumber  id,
Properties  properties 
)

Add Properties to the given type's record in *this.

Parameters
id
properties
Returns
the given id.

Definition at line 106 of file PeriodicTable.cpp.

110{
111 typename Hadits::iterator hdt = Find(id);
112 BIO_SANITIZE_AT_SAFETY_LEVEL_2(hdt == this->m_hadits.end(), ,
113 return InvalidId());
114
115 LockThread();
116 Element* element = ForceCast< Element* >(hdt->m_type);
117 if (!element)
118 {
119 element = new Element();
120 hdt->m_type = element->AsWave();
121 }
122 element->Import< Property >(properties);
123 UnlockThread();
124 return id;
125}
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)

References bio::physical::Class< T >::AsWave(), BIO_SANITIZE_AT_SAFETY_LEVEL_2, bio::physical::Perspective< AtomicNumber >::Find(), bio::chemical::UnorderedStructureInterface::Import(), bio::physical::Perspective< AtomicNumber >::InvalidId(), bio::ThreadSafe::LockThread(), bio::physical::Perspective< AtomicNumber >::m_hadits, and bio::ThreadSafe::UnlockThread().

Referenced by RecordPropertiesOf(), and RecordPropertyOf().

◆ RecordPropertiesOf() [2/3]

AtomicNumber bio::chemical::PeriodicTableImplementation::RecordPropertiesOf ( Name  name,
Properties  properties 
)

Add Properties to the given type's record in *this.

Parameters
name
properties
Returns
the id of the given name.

Definition at line 127 of file PeriodicTable.cpp.

131{
132 return RecordPropertiesOf(
133 GetIdFromName(name),
134 properties
135 );
136}
AtomicNumber RecordPropertiesOf(AtomicNumber id, Properties properties)

References bio::physical::Perspective< AtomicNumber >::GetIdFromName(), and RecordPropertiesOf().

◆ RecordPropertiesOf() [3/3]

template<typename T >
AtomicNumber bio::chemical::PeriodicTableImplementation::RecordPropertiesOf ( Properties  properties)
inline

Add Properties to the given type's record in *this.

Template Parameters
T
Parameters
properties
Returns
the id of the given type.

Definition at line 186 of file PeriodicTable.h.

187 {
188 return RecordPropertiesOf(
189 TypeName< T >().c_str(),
190 properties
191 );
192 }

References RecordPropertiesOf().

◆ RecordPropertyOf() [1/3]

AtomicNumber bio::chemical::PeriodicTableImplementation::RecordPropertyOf ( AtomicNumber  id,
Property  property 
)

Add a Property to the given type's record in *this.

Parameters
id
property
Returns
the id given.

Definition at line 82 of file PeriodicTable.cpp.

86{
87 Properties properties;
88 properties.push_back(property);
89 return RecordPropertiesOf(
90 id,
91 properties
92 );
93}

References bio::Properties, and RecordPropertiesOf().

Referenced by RecordPropertyOf().

◆ RecordPropertyOf() [2/3]

AtomicNumber bio::chemical::PeriodicTableImplementation::RecordPropertyOf ( Name  name,
Property  property 
)

Add a Property to the given type's record in *this.

Parameters
name
property
Returns
the id of the given name.

Definition at line 95 of file PeriodicTable.cpp.

99{
100 return RecordPropertyOf(
101 GetIdFromName(name),
102 property
103 );
104}
AtomicNumber RecordPropertyOf(AtomicNumber id, Property property)

References bio::physical::Perspective< AtomicNumber >::GetIdFromName(), and RecordPropertyOf().

◆ RecordPropertyOf() [3/3]

template<typename T >
AtomicNumber bio::chemical::PeriodicTableImplementation::RecordPropertyOf ( Property  property)
inline

Add a Property to the given type's record in *this.

Template Parameters
T
Parameters
property
Returns
the id of the given typo.

Definition at line 149 of file PeriodicTable.h.

150 {
151 return RecordPropertyOf(
152 TypeName< T >().c_str(),
153 property
154 );
155 }

References RecordPropertyOf().


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