PUMA Library Reference Manual
Puma::UnitManager Class Reference

#include <Puma/UnitManager.h>

Description

Class to manage the units built to parse the files of the source project.

Public Types

typedef std::map< std::string, Unit * > UMap
 Name to unit map type. More...
 
typedef UMap::value_type UMapEntry
 Name to unit map entry type. More...
 
typedef UMap::iterator UMapIter
 Name to unit map iterator type. More...
 

Public Member Functions

 UnitManager (ErrorStream &err)
 Constructor. More...
 
virtual ~UnitManager ()
 Destructor. More...
 
UMapgetTable () const
 Get the unit management table. More...
 
Tokenizertokenizer () const
 Get the tokenizer (scanner) that is used by scanSource() to tokenize sources. More...
 
void tokenizer (Tokenizer *tokenizer)
 Set the tokenizer (scanner) to be used by scanSource() to tokenize sources. More...
 
void add (Unit *unit)
 Add a token unit to the manager. More...
 
Unitget (const char *name, bool isfile=false) const
 Get a managed unit by name. More...
 
void discard (const char *name, bool isfile=false, bool destroy=true) const
 Discard a unit managed by this unit manager. More...
 
void discardAll (bool destroy=true) const
 Discard all named units managed by this unit manager. More...
 
void discardNonames ()
 Discard all no-name units managed by this unit manager. More...
 
UnitscanSource (const char *name, Source *in=0, bool isfile=false)
 Scan the tokens from the given input source and create a unit from it. More...
 
void print (const char *name, bool isfile=false, std::ostream &out=std::cout) const
 Print a named unit on the given output stream. More...
 
void init ()
 Initialize the unit manager and the managed units for the next parse process. More...
 

Member Typedef Documentation

◆ UMap

typedef std::map<std::string, Unit*> Puma::UnitManager::UMap

Name to unit map type.

◆ UMapEntry

typedef UMap::value_type Puma::UnitManager::UMapEntry

Name to unit map entry type.

◆ UMapIter

typedef UMap::iterator Puma::UnitManager::UMapIter

Name to unit map iterator type.

Constructor & Destructor Documentation

◆ UnitManager()

Puma::UnitManager::UnitManager ( ErrorStream err)
inline

Constructor.

Parameters
errError stream to use for reporting errors.

◆ ~UnitManager()

virtual Puma::UnitManager::~UnitManager ( )
virtual

Destructor.

Deletes all managed units.

Member Function Documentation

◆ add()

void Puma::UnitManager::add ( Unit unit)

Add a token unit to the manager.

Parameters
unitThe unit to add.

◆ discard()

void Puma::UnitManager::discard ( const char *  name,
bool  isfile = false,
bool  destroy = true 
) const

Discard a unit managed by this unit manager.

Parameters
nameThe name of the unit to remove.
isfileTrue to indicate that the given name refers to a file (defaults to false).
destroyTrue to indicate that the unit shall be destroyed (defaults to true).

◆ discardAll()

void Puma::UnitManager::discardAll ( bool  destroy = true) const

Discard all named units managed by this unit manager.

Parameters
destroyTrue to indicate that the units shall be destroyed (defaults to true).

◆ discardNonames()

void Puma::UnitManager::discardNonames ( )

Discard all no-name units managed by this unit manager.

◆ get()

Unit* Puma::UnitManager::get ( const char *  name,
bool  isfile = false 
) const

Get a managed unit by name.

Parameters
nameThe name of the unit to get.
isfileTrue to indicate that the given name refers to a file (defaults to false).
Returns
A pointer to the unit.

◆ getTable()

UMap& Puma::UnitManager::getTable ( ) const
inline

Get the unit management table.

Returns
A reference to the unit table.

◆ init()

void Puma::UnitManager::init ( )

Initialize the unit manager and the managed units for the next parse process.

◆ print()

void Puma::UnitManager::print ( const char *  name,
bool  isfile = false,
std::ostream &  out = std::cout 
) const

Print a named unit on the given output stream.

Parameters
nameThe name of the unit to print.
isfileTrue to indicate that the given name refers to a file (defaults to false).
outThe output stream, defaults to std::cout.

◆ scanSource()

Unit* Puma::UnitManager::scanSource ( const char *  name,
Source in = 0,
bool  isfile = false 
)

Scan the tokens from the given input source and create a unit from it.

The new unit is added to the unit manager.

Parameters
nameThe name of the unit to create.
inThe input source.
isfileTrue to indicate that the given name refers to a file (defaults to false).
Returns
A pointer to the new unit created.

◆ tokenizer() [1/2]

Tokenizer* Puma::UnitManager::tokenizer ( ) const
inline

Get the tokenizer (scanner) that is used by scanSource() to tokenize sources.

Returns
A pointer to the tokenizer used.

◆ tokenizer() [2/2]

void Puma::UnitManager::tokenizer ( Tokenizer tokenizer)
inline

Set the tokenizer (scanner) to be used by scanSource() to tokenize sources.

Parameters
tokenizerThe tokenizer to use.