#include <typemodel.hh>
Public Types | |
enum | Category { NullType = 0, Array, Pointer, Numeric, Enum, Compound, Opaque, Container, NumberOfValidCategories } |
typedef std::map< Type const *, Type const * > | RecursionStack |
Public Member Functions | |
bool | canCastTo (Type const &to) const |
virtual std::set< Type const * > | dependsOn () const =0 |
std::string | getBasename () const |
Category | getCategory () const |
MetaData & | getMetaData () const |
MetaData::Values | getMetaData (std::string const &key) const |
std::string | getName () const |
std::string | getNamespace () const |
size_t | getSize () const |
virtual unsigned int | getTrailingPadding () const |
bool | isNull () const |
bool | isSame (Type const &other) const |
Type const & | merge (Registry ®istry) const |
virtual Type const & | merge (Registry ®istry, RecursionStack &stack) const |
virtual void | mergeMetaData (Type const &other) const |
virtual void | modifiedDependencyAliases (Registry ®istry) const |
bool | operator!= (Type const &with) const |
bool | operator== (Type const &with) const |
virtual bool | resize (Registry ®istry, std::map< std::string, std::pair< size_t, size_t > > &new_sizes) |
void | setName (const std::string &name) |
void | setSize (size_t size) |
Type (Type const &type) | |
virtual | ~Type () |
Protected Member Functions | |
virtual bool | do_compare (Type const &other, bool equality, std::map< Type const *, Type const * > &stack) const |
virtual Type * | do_merge (Registry ®istry, RecursionStack &stack) const =0 |
virtual bool | do_resize (Registry &into, std::map< std::string, std::pair< size_t, size_t > > &new_sizes) |
bool | rec_compare (Type const &left, Type const &right, bool equality, RecursionStack &stack) const |
Type const * | try_merge (Registry ®istry, RecursionStack &stack) const |
Type (const std::string &name, size_t size, Category category) | |
Private Member Functions | |
Type & | operator= (Type const &type) |
Static Private Member Functions | |
static bool | isValidIdentifier (const std::string &identifier) |
Private Attributes | |
Category | m_category |
MetaData * | m_metadata |
This is kept as pointer so that it can be modified even if the Type. | |
std::string | m_name |
size_t | m_size |
Base class for all type definitions
Definition at line 70 of file typemodel.hh.
typedef std::map<Type const*, Type const*> Typelib::Type::RecursionStack |
Foreign => local mapping for merge() and isSame()
Definition at line 168 of file typemodel.hh.
Definition at line 74 of file typemodel.hh.
Typelib::Type::Type | ( | const std::string & | name, |
size_t | size, | ||
Category | category | ||
) | [protected] |
Definition at line 21 of file typemodel.cc.
Typelib::Type::~Type | ( | ) | [virtual] |
Definition at line 37 of file typemodel.cc.
Typelib::Type::Type | ( | Type const & | type | ) |
Definition at line 29 of file typemodel.cc.
bool Typelib::Type::canCastTo | ( | Type const & | to | ) | const |
Returns true if to
can be used to manipulate a value that is described by from
Definition at line 63 of file typemodel.cc.
virtual std::set<Type const*> Typelib::Type::dependsOn | ( | ) | const [pure virtual] |
The set of types this type depends upon
This method returns the set of types that are directly depended-upon by this type
Implemented in Typelib::Indirect, Typelib::Compound, Typelib::Enum, Typelib::Numeric, Typelib::OpaqueType, and Typelib::NullType.
bool Typelib::Type::do_compare | ( | Type const & | other, |
bool | equality, | ||
std::map< Type const *, Type const * > & | stack | ||
) | const [protected, virtual] |
Method that is implemented by type definitions to compare *this with other
.
If equality
is true, the method must check for strict equality. If it is false, it must check if other
can be used to manipulate values of type *this
.
For instance, let's consider a compound that has padding bytes, and assume that *this and other
have different padding (but are the same on every other aspects). do_compare should then return true if equality is false, and false if equality is true.
It must use rec_compare to check for indirections (i.e. for recursive calls).
The base definition compares the name, size and category of the types.
Reimplemented in Typelib::OpaqueType.
Definition at line 101 of file typemodel.cc.
virtual Type* Typelib::Type::do_merge | ( | Registry & | registry, |
RecursionStack & | stack | ||
) | const [protected, pure virtual] |
Called by Type::merge when the type does not exist in registry
already. This method has to create a new type in registry that matches the type definition of *this.
All types referenced by *this must be moved to their equivalent in registry
.
Implemented in Typelib::Container, Typelib::Pointer, Typelib::Array, Typelib::Compound, Typelib::Enum, Typelib::Numeric, Typelib::OpaqueType, and Typelib::NullType.
bool Typelib::Type::do_resize | ( | Registry & | into, |
std::map< std::string, std::pair< size_t, size_t > > & | new_sizes | ||
) | [protected, virtual] |
Implementation of the actual resizing. Called by resize()
Reimplemented in Typelib::Array, Typelib::Indirect, and Typelib::Compound.
Definition at line 154 of file typemodel.cc.
std::string Typelib::Type::getBasename | ( | ) | const |
The type name without the namespace
Definition at line 43 of file typemodel.cc.
Type::Category Typelib::Type::getCategory | ( | ) | const |
The type category
Definition at line 46 of file typemodel.cc.
MetaData & Typelib::Type::getMetaData | ( | ) | const |
Returns the metadata for this type
Definition at line 170 of file typemodel.cc.
MetaData::Values Typelib::Type::getMetaData | ( | std::string const & | key | ) | const |
Returns the metadata values declared for this particular key
Definition at line 175 of file typemodel.cc.
std::string Typelib::Type::getName | ( | ) | const |
The type full name (including namespace)
Definition at line 42 of file typemodel.cc.
std::string Typelib::Type::getNamespace | ( | ) | const |
The type namespace
Definition at line 44 of file typemodel.cc.
size_t Typelib::Type::getSize | ( | ) | const |
Size in bytes of a value
Definition at line 50 of file typemodel.cc.
unsigned int Typelib::Type::getTrailingPadding | ( | ) | const [virtual] |
Returns the number of bytes that are unused at the end of the compound
Reimplemented in Typelib::Compound.
Definition at line 73 of file typemodel.cc.
bool Typelib::Type::isNull | ( | ) | const |
true if this type is null
Definition at line 51 of file typemodel.cc.
bool Typelib::Type::isSame | ( | Type const & | other | ) | const |
Deep check that other
defines the same type than self. Basic checks on name, size and category are performed by ==
Definition at line 54 of file typemodel.cc.
static bool Typelib::Type::isValidIdentifier | ( | const std::string & | identifier | ) | [static, private] |
Checks that identifier
is a valid type name
Type const & Typelib::Type::merge | ( | Registry & | registry | ) | const |
Merges this type into registry:
creates a type equivalent to this one in the target registry, reusing possible equivalent types already present in +registry+.
Definition at line 104 of file typemodel.cc.
Type const & Typelib::Type::merge | ( | Registry & | registry, |
RecursionStack & | stack | ||
) | const [virtual] |
Base merge method. The default implementation should be fine for most types.
Call try_merge to check if a type equivalent to *this exists in registry
, and do_merge to create a copy of *this in registry
.
Reimplemented in Typelib::Indirect.
Definition at line 128 of file typemodel.cc.
void Typelib::Type::mergeMetaData | ( | Type const & | other | ) | const [virtual] |
Merge metadata information from the given type into this
Reimplemented in Typelib::Compound.
Definition at line 180 of file typemodel.cc.
void Typelib::Type::modifiedDependencyAliases | ( | Registry & | registry | ) | const [virtual] |
Called by the registry if one (or more) of this type's dependencies is aliased
The default implementation does nothing. It is reimplemented in types for which the name is built from the dependencies' name
Reimplemented in Typelib::Indirect, and String.
Definition at line 47 of file typemodel.cc.
bool Typelib::Type::operator!= | ( | Type const & | with | ) | const |
Definition at line 52 of file typemodel.cc.
bool Typelib::Type::operator== | ( | Type const & | with | ) | const |
Definition at line 53 of file typemodel.cc.
bool Typelib::Type::rec_compare | ( | Type const & | left, |
Type const & | right, | ||
bool | equality, | ||
RecursionStack & | stack | ||
) | const [protected] |
Called by do_compare to compare +left+ to +right+. This method takes into account potential loops in the recursion
See do_compare for a description of the equality flag.
One type cannot be equal to two different types. So either we are already comparing left and right and it is fine (return true). Or we are comparing it with a different type and that means the two types are different (return false)
Definition at line 76 of file typemodel.cc.
bool Typelib::Type::resize | ( | Registry & | registry, |
std::map< std::string, std::pair< size_t, size_t > > & | new_sizes | ||
) | [virtual] |
Update this type to reflect a type resize. The default implementation will resize *this if it is listed in new_sizes
. new_sizes gets updated with the types that are modified.
This is not to be called directly. Only use Registry::resize().
Definition at line 140 of file typemodel.cc.
void Typelib::Type::setName | ( | const std::string & | name | ) |
Changes the type name. Never use once the type has been added to a registry
Definition at line 45 of file typemodel.cc.
void Typelib::Type::setSize | ( | size_t | size | ) |
Changes the type size. Don't use that unless you know what you are doing. In particular, don't use it once the type is used in a Compound.
Definition at line 49 of file typemodel.cc.
Type const * Typelib::Type::try_merge | ( | Registry & | registry, |
RecursionStack & | stack | ||
) | const [protected] |
Checks if there is already a type with the same name and definition than *this in registry
. If that is the case, returns it, otherwise returns NULL;
If there is a type with the same name, but whose definition mismatches, throws DefinitionMismatch
Definition at line 109 of file typemodel.cc.
Category Typelib::Type::m_category [private] |
Reimplemented in Typelib::Numeric.
Definition at line 91 of file typemodel.hh.
MetaData* Typelib::Type::m_metadata [private] |
This is kept as pointer so that it can be modified even if the Type.
Definition at line 95 of file typemodel.hh.
std::string Typelib::Type::m_name [private] |
Definition at line 88 of file typemodel.hh.
size_t Typelib::Type::m_size [private] |
Definition at line 90 of file typemodel.hh.