Develop Biology
The language of life
bio::chemical::Elementary< T > Class Template Reference

#include <Elementary.h>

+ Inheritance diagram for bio::chemical::Elementary< T >:

Public Member Functions

 Elementary ()
 
 Elementary (const Properties properties)
 
virtual ~Elementary ()
 
void RegisterProperties (const Properties properties)
 

Static Public Attributes

static bool hasRegistered
 

Detailed Description

template<typename T>
class bio::chemical::Elementary< T >

Elements are used to make entries in the PeriodicTable. When constructing an Elementary<>, you must provide its Properties.

When to use: You have a class that implements an interface and/or an interface which will be non-virtually inherited by downstream classes and you want those downstream classes to be able to call a method for each of your inherited classes without having to force the child classes to disambiguate each parent instance in a virtual override of your class method.

How to use:

  1. Define some abstract base class with the methods you wish to call (e.g. AbstractMotif, with ImportImplementation).
  2. Add a static Properties GetClassProperties() method to the abstract base which returns some unique Properties for the feature you're building (NOTE: this should also be the return value of the virtual physical::Wave::GetProperties() method).
  3. Define however many implementations of that abstract base as you would like (e.g. templated children, like StructuralComponentImplementation).
  4. Define an interface class that will call the appropriate interface methods (e.g. Structure).
  5. Define high-level wrappers around the interface(s) and interface with virtual inheritance for the interface (e.g. UnorderedMotif).
  6. Make your wrapper classes derive from Elementary with CRTP (provide the wrapper class as T for Elementary<T>) and provide your base class GetClassProperties() to the Elementary constructor.

Once all that is done and you utilize Atom Bonding methods (or derive from chemical::Class) you will have essentially inverted the inheritance tree, allowing base classes to call what would be derived class methods without the derived classes having to implement those methods. To elaborate, if you have a class that derives from multiple high-level wrappers, under normal inheritance, you would have to create a MyImplementation() override method of the abstract base class method which calls all the different parent class methods (e.g. operator== comparing all parent equivalencies). If you do not do this, the method becomes ambiguous because each wrapper provides an equally valid interface. However, by recording which wrappers have the properties of the abstract base, you can call each wrapper's interface of a base class method by casting the wrapper to the base and calling the virtual function (the base is NOT virtually inherited). The reason Elementary must be used on the wrapper and not on your multi-wrapper child is that doing so would create multiple eligible Bonds within an Atom, some of which would have ambiguous definitions, as mentioned.

Template Parameters
T

Definition at line 51 of file Elementary.h.

Constructor & Destructor Documentation

◆ Elementary() [1/2]

template<typename T >
bio::chemical::Elementary< T >::Elementary ( const Properties  properties)
inline
Parameters
properties

Definition at line 76 of file Elementary.h.

77 {
78 RegisterProperties(properties);
79 }
void RegisterProperties(const Properties properties)
Definition: Elementary.h:64

References bio::chemical::Elementary< T >::RegisterProperties().

◆ Elementary() [2/2]

template<typename T >
bio::chemical::Elementary< T >::Elementary ( )
inline

If you don't know the class Properties at time of construction, you can use this. Though RegisterProperties should be as close to, if not directly, a constexpr and should be known even before *this is constructed.

Definition at line 85 of file Elementary.h.

86 {
87
88 }

◆ ~Elementary()

template<typename T >
virtual bio::chemical::Elementary< T >::~Elementary ( )
inlinevirtual

Definition at line 94 of file Elementary.h.

95 {
96
97 }

Member Function Documentation

◆ RegisterProperties()

template<typename T >
void bio::chemical::Elementary< T >::RegisterProperties ( const Properties  properties)
inline

Records the given Properties as those for the type T within the PeriodicTable.

Parameters
properties

Definition at line 64 of file Elementary.h.

65 {
66 if (!hasRegistered)
67 {
68 PeriodicTable::Instance().RecordPropertiesOf< T >(properties);
69
70 }
71 }
static bool hasRegistered
Definition: Elementary.h:58

References bio::chemical::Elementary< T >::hasRegistered.

Referenced by bio::chemical::Elementary< T >::Elementary().

Member Data Documentation

◆ hasRegistered

template<typename T >
bool bio::chemical::Elementary< T >::hasRegistered
static

Ensure we only Record the Properties of T once. They should always be the same.

Definition at line 58 of file Elementary.h.

Referenced by bio::chemical::Elementary< T >::RegisterProperties().


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