Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Private Member Functions | Private Attributes
Typelib::Type Class Reference

#include <typemodel.hh>

Inheritance diagram for Typelib::Type:
Inheritance graph
[legend]

List of all members.

Public Types

enum  Category {
  NullType = 0, Array, Pointer, Numeric,
  Enum, Compound, Opaque, Container
}
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
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 &registry) const
virtual Type const & merge (Registry &registry, RecursionStack &stack) const
virtual void modifiedDependencyAliases (Registry &registry) const
bool operator!= (Type const &with) const
bool operator== (Type const &with) const
virtual bool resize (Registry &registry, std::map< std::string, std::pair< size_t, size_t > > &new_sizes)
void setName (const std::string &name)
void setSize (size_t size)
virtual ~Type ()

Static Public Attributes

static const int ValidCategories = Compound + 1

Protected Member Functions

virtual bool do_compare (Type const &other, bool equality, std::map< Type const *, Type const * > &stack) const
virtual Typedo_merge (Registry &registry, 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 &registry, RecursionStack &stack) const
 Type (const std::string &name, size_t size, Category category)

Static Private Member Functions

static bool isValidIdentifier (const std::string &identifier)

Private Attributes

Category m_category
std::string m_name
size_t m_size

Detailed Description

Base class for all type definitions

Definition at line 20 of file typemodel.hh.


Member Typedef Documentation

typedef std::map<Type const*, Type const*> Typelib::Type::RecursionStack

Foreign => local mapping for merge() and isSame()

Definition at line 111 of file typemodel.hh.


Member Enumeration Documentation

Enumerator:
NullType 
Array 
Pointer 
Numeric 
Enum 
Compound 
Opaque 
Container 

Definition at line 24 of file typemodel.hh.


Constructor & Destructor Documentation

Typelib::Type::Type ( const std::string &  name,
size_t  size,
Category  category 
) [protected]

Definition at line 22 of file typemodel.cc.

Typelib::Type::~Type ( ) [virtual]

Definition at line 27 of file typemodel.cc.


Member Function Documentation

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 50 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 88 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 138 of file typemodel.cc.

std::string Typelib::Type::getBasename ( ) const

The type name without the namespace

Definition at line 30 of file typemodel.cc.

The type category

Definition at line 33 of file typemodel.cc.

std::string Typelib::Type::getName ( void  ) const

The type full name (including namespace)

Definition at line 29 of file typemodel.cc.

std::string Typelib::Type::getNamespace ( ) const

The type namespace

Definition at line 31 of file typemodel.cc.

size_t Typelib::Type::getSize ( ) const

Size in bytes of a value

Definition at line 37 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 60 of file typemodel.cc.

bool Typelib::Type::isNull ( ) const

true if this type is null

Definition at line 38 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 41 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 91 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 112 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 34 of file typemodel.cc.

bool Typelib::Type::operator!= ( Type const &  with) const

Definition at line 39 of file typemodel.cc.

bool Typelib::Type::operator== ( Type const &  with) const

Definition at line 40 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 63 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().

Returns:
true if this type has been modified, and false otherwise.

Definition at line 124 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 32 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 36 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 96 of file typemodel.cc.


Member Data Documentation

Reimplemented in Typelib::Numeric.

Definition at line 41 of file typemodel.hh.

std::string Typelib::Type::m_name [private]

Definition at line 38 of file typemodel.hh.

size_t Typelib::Type::m_size [private]

Definition at line 40 of file typemodel.hh.

const int Typelib::Type::ValidCategories = Compound + 1 [static]

Reimplemented in Typelib::Numeric.

Definition at line 35 of file typemodel.hh.


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


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Mon Oct 6 2014 03:17:12