COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Map< KEY, DATA > Class Template Reference

#include <Map.hpp>

Inherits Component.

Classes

class  Compare
 
class  LessThan
 

Public Types

typedef KEY key_type
 Associative Container – The map's key type, Key. More...
 
typedef DATA data_type
 Pair Associative Container – The type of object associated with the keys. More...
 
typedef std::pair< key_type, data_typevalue_type
 The type of object, pair<const key_type, data_type>, stored in the map. More...
 
typedef std::vector< value_type >::iterator iterator
 iterator definition for use in stl algorithms More...
 
typedef std::vector< value_type >::const_iterator const_iterator
 const_iterator definition for use in stl algorithms More...
 
- Public Types inherited from Component
typedef ComponentIterator< Componentiterator
 type of the iterator to Component More...
 
typedef ComponentIterator< Component const > const_iterator
 type of the iterator to constant Component More...
 
- Public Types inherited from SignalHandler
typedef std::vector< SignalPtrstorage_t
 storage type for signals More...
 

Public Member Functions

 Map (const std::string &name)
 
virtual ~Map ()
 Virtual destructor. More...
 
void reserve (size_t max_size)
 Reserve memory. More...
 
void copy_std_map (std::map< key_type, data_type > &map)
 Copy a std::map into the Map. More...
 
Uint push_back (const key_type &key, const data_type &data)
 Insert pair without any checks if it is already present. More...
 
std::pair< iterator, bool > insert (const value_type &v)
 Insert pair the same way a std::map would. More...
 
iterator find (const key_type &key)
 Find the iterator matching with the given KEY. More...
 
const_iterator find (const key_type &key) const
 Find the iterator matching with the given KEY. More...
 
void erase (iterator itr)
 Erase the given iterator from the map. More...
 
bool erase (const key_type &key)
 Erase the entry wit given key from the map. More...
 
bool exists (const key_type &key)
 Check if the given KEY is existing in the Map. More...
 
bool exists (const key_type &key) const
 Check if the given KEY is existing in the Map. More...
 
void clear ()
 Clear the content of the map. More...
 
size_t size () const
 Get the number of pairs already inserted. More...
 
size_t capacity () const
 Get the capacity of the map (memory allocated) More...
 
data_typeoperator[] (const key_type &key)
 Overloading of the operator"[]" for assignment AND insertion. More...
 
const data_typeoperator[] (const key_type &key) const
 Overloading of the operator"[]" for assignment AND insertion. More...
 
void sort_keys ()
 Sort all the pairs in the map by key. More...
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
- Public Member Functions inherited from Component
 Component (const std::string &name)
 
virtual ~Component ()
 Virtual destructor. More...
 
const std::string & name () const
 Access the name of the component. More...
 
void rename (const std::string &name)
 Rename the component. More...
 
URI uri () const
 Construct the full path. More...
 
void complete_path (URI &path) const
 
Handle< Componentaccess_component (const URI &path) const
 
Handle< Componentaccess_component_checked (const URI &path)
 
Handle< Component const > access_component_checked (const URI &path) const
 
Handle< Componenthandle ()
 Get a handle to the component. More...
 
Handle< Component const > handle () const
 
template<typename ComponentT >
Handle< ComponentT > handle ()
 
template<typename ComponentT >
Handle< ComponentT const > handle () const
 
Handle< Componentparent () const
 
Handle< Component const > root () const
 
Handle< Componentroot ()
 
Handle< Componentget_child (const std::string &name)
 
Handle< Component const > get_child (const std::string &name) const
 
Handle< Componentget_child_checked (const std::string &name)
 
Handle< Component const > get_child_checked (const std::string &name) const
 
Handle< Componentcreate_component (const std::string &name, const std::string &builder)
 Build a (sub)component of this component using the extended type_name of the component. More...
 
template<typename T >
Handle< T > create_component (const std::string &name)
 Create a (sub)component of this component automatically cast to the specified type. More...
 
template<typename T >
Handle< T > create_static_component (const std::string &name)
 Create a static "always there" subcomponent. More...
 
Componentadd_component (const boost::shared_ptr< Component > &subcomp)
 Add the passed component as a subcomponent. More...
 
void add_link (Component &linked_component)
 
boost::shared_ptr< Componentremove_component (const std::string &name)
 Remove a (sub)component of this component. More...
 
boost::shared_ptr< Componentremove_component (Component &subcomp)
 Remove a (sub)component of this component. More...
 
void clear ()
 Remove all sub-components of this component, except for the static ones. More...
 
void move_to (Component &to_parent)
 
std::string tree (bool basic_mode=false, Uint depth=0, Uint recursion_level=0) const
 
std::string info (const std::string &what=std::string("cospt")) const
 
size_t count_children () const
 
virtual std::string derived_type_name () const =0
 
PropertyListproperties ()
 
const PropertyListproperties () const
 
OptionListoptions ()
 
const OptionListoptions () const
 
void reset_options ()
 Reset all options to their default value. More...
 
void configure_option_recursively (const std::string &optname, const boost::any &val)
 
Componentmark_basic ()
 marks this component as basic. More...
 
template<typename ComponentT >
void put_components (std::vector< boost::shared_ptr< ComponentT > > &vec, const bool recurse)
 
template<typename ComponentT >
void put_components (std::vector< boost::shared_ptr< ComponentT const > > &vec, const bool recurse) const
 
template<>
void put_components (std::vector< boost::shared_ptr< Component > > &vec, const bool recurse)
 
template<>
void put_components (std::vector< boost::shared_ptr< Component const > > &vec, const bool recurse) const
 
Component::iterator begin ()
 The begin iterator for a range containing Components. More...
 
Component::iterator end ()
 The end iterator for a range containing Components. More...
 
Component::const_iterator begin () const
 The begin iterator for a range containing Components (const version) More...
 
Component::const_iterator end () const
 The end iterator for a range containing Components (const version) More...
 
Component::iterator recursive_begin ()
 The begin iterator for a recursive range containing Components. More...
 
Component::iterator recursive_end ()
 The end iterator for a recursive range containing Components. More...
 
Component::const_iterator recursive_begin () const
 The begin iterator for a recursive range containing Components (const version) More...
 
Component::const_iterator recursive_end () const
 The end iterator for a recursive range containing Components (const version) More...
 
template<typename T >
Handle< T > create_component (const std::string &name, const std::string &builder)
 Create a component using the reduced builder name. More...
 
void signal_configure (SignalArgs &args)
 configures all the options on this class More...
 
void signal_create_component (SignalArgs &args)
 creates a component from this component More...
 
void signal_delete_component (SignalArgs &args)
 delete this component More...
 
void signal_move_component (SignalArgs &args)
 moves a component from this component to another More...
 
void signal_list_tree (SignalArgs &args) const
 lists the sub components and puts them on the xml_tree More...
 
void signal_list_tree_recursive (SignalArgs &args) const
 prints tree recursively More...
 
void signal_list_properties (SignalArgs &args) const
 lists the properties of this component More...
 
void signal_list_options (SignalArgs &args) const
 lists the properties of this component More...
 
void signal_list_options_recursive (SignalArgs &args) const
 prints all options recursive More...
 
void signal_list_signals (SignalArgs &args) const
 lists the signals of this component More...
 
void signal_list_signals_recursive (SignalArgs &args) const
 prints all signals recursive More...
 
void signal_print_info (SignalArgs &args) const
 gets info on this component More...
 
void signal_print_tree (SignalArgs &args) const
 signal to print the tree More...
 
void signature_print_tree (SignalArgs &args) const
 signature to signal_print_tree More...
 
void signal_rename_component (SignalArgs &args)
 renames this component More...
 
void signal_save_tree (SignalArgs &args)
 dumps the tree to a file More...
 
void signal_list_content (SignalArgs &args)
 gives information about this component such as options, signals, ... More...
 
void signal_signature (SignalArgs &args)
 Gives a signal signature, if any. More...
 
void signature_create_component (SignalArgs &args)
 
void signature_rename_component (SignalArgs &args)
 
void signature_move_component (SignalArgs &args)
 
void signal_store_timings (SignalArgs &args)
 Signal to store the timings (if enabled) into properties, i.e. for readout from python or the GUI. More...
 
void signal_clear (SignalArgs &args)
 Signal to remove all sub-components. More...
 
void signal_reset_options (SignalArgs &args)
 Signal to set all options to their default value. More...
 
void signal_add_tag (SignalArgs &args)
 Signal to add a tag. More...
 
void signature_add_tag (SignalArgs &args)
 
- Public Member Functions inherited from SignalHandler
 ~SignalHandler ()
 
const storage_tsignal_list () const
 
SignalPtr signal (const SignalID &sname)
 
SignalCPtr signal (const SignalID &sname) const
 
SignalRet call_signal (const SignalID &sname, SignalArgs &sinput)
 Calls the signal by providing its name and input. More...
 
SignalRet call_signal (const SignalID &sname, std::vector< std::string > &sinput)
 Calls the signal by providing its name and input. More...
 
bool signal_exists (const SignalID &sname) const
 Checks if a signal exists or not. More...
 
Signalregist_signal (const SignalID &sname)
 Regist signal. More...
 
void unregist_signal (const SignalID &sname)
 Unregist signal. More...
 
- Public Member Functions inherited from ConnectionManager
 ~ConnectionManager ()
 destructor closes all connections More...
 
Connectionconnection (const std::string &name)
 
Connectionmanage_connection (const std::string &name)
 manages a connection (creates if necessary) More...
 
- Public Member Functions inherited from TaggedObject
 TaggedObject ()
 Constructor. More...
 
bool has_tag (const std::string &tag) const
 
void add_tag (const std::string &tag)
 
std::vector< std::string > get_tags () const
 
void remove_tag (const std::string &tag)
 

Static Public Member Functions

static std::string type_name ()
 Get the class name. More...
 
- Static Public Member Functions inherited from Component
static std::string type_name ()
 Get the class name. More...
 

Static Private Member Functions

static bool unique_key (const value_type &val1, const value_type &val2)
 

Private Attributes

bool m_sorted
 
std::vector< value_typem_vectorMap
 storage of the inserted data More...
 

Additional Inherited Members

- Public Attributes inherited from SignalHandler
storage_t m_signals
 storage of the signals More...
 
- Protected Member Functions inherited from Component
Componentadd_static_component (const boost::shared_ptr< Component > &subcomp)
 Add a static (sub)component of this component. More...
 
void raise_tree_updated_event ()
 raise event that the path has changed More...
 

Detailed Description

template<typename KEY, typename DATA>
class cf3::common::Map< KEY, DATA >

This component class represents a "cheap" (from the point of view of the memory requirements) map with SINGLE key that gives the same performance in searching of a std::map (the number of comparisons is <= 2*log(size)+1. Since the high memory storage is an issue with the standard std::map, this class offer a valid efficient alternative to it. Map that is just an Adapter of std::vector<std::pair<KEY,DATA> >. The advantage of this map is that it is faster to construct (build vector, sort once) and uses less memory than std::map. The disadvantage is that it is much slower when elements need to be looked up while the map is being constructed. The class is parameterized with the types of the key and the type of the value

Precondition
this map can handle KEYs for which the operators "<" and ">" are available
before using find() the Map has to be sorted. This will happen automatically
the situation in which this map must be used is a situation in which you first insert ALL the pairs, then you sort (sort_keys() is a demanding operation that must be applied only once!!) and then you start searching with find(). Consider using 2 seperate vectors (one for keys and one for elements) It will be easier on the memory allocator, and it will provide for faster access (multiple keys will be loaded in one cacheline when searching)
Author
Andrea Lani
Tiago Quintino
Willem Deconinck

Definition at line 43 of file Map.hpp.

Member Typedef Documentation

typedef std::vector<value_type>::const_iterator const_iterator

const_iterator definition for use in stl algorithms

Definition at line 57 of file Map.hpp.

typedef DATA data_type

Pair Associative Container – The type of object associated with the keys.

Definition at line 50 of file Map.hpp.

typedef std::vector<value_type>::iterator iterator

iterator definition for use in stl algorithms

Definition at line 55 of file Map.hpp.

typedef KEY key_type

Associative Container – The map's key type, Key.

Definition at line 48 of file Map.hpp.

typedef std::pair<key_type, data_type> value_type

The type of object, pair<const key_type, data_type>, stored in the map.

Definition at line 52 of file Map.hpp.

Constructor & Destructor Documentation

Map ( const std::string &  name)
inline

Contructor

Parameters
[in]nameof the component

Definition at line 63 of file Map.hpp.

virtual ~Map ( )
inlinevirtual

Virtual destructor.

Definition at line 69 of file Map.hpp.

Member Function Documentation

Map< KEY, DATA >::iterator begin ( )
inline
Returns
the iterator pointing at the first element

Definition at line 453 of file Map.hpp.

Map< KEY, DATA >::const_iterator begin ( ) const
inline
Returns
the const_iterator pointing at the first element

Definition at line 461 of file Map.hpp.

size_t capacity ( ) const

Get the capacity of the map (memory allocated)

Definition at line 398 of file Map.hpp.

void clear ( )
inline

Clear the content of the map.

Definition at line 390 of file Map.hpp.

void copy_std_map ( std::map< key_type, data_type > &  map)

Copy a std::map into the Map.

Parameters
[in]mapThe map to copy

Definition at line 293 of file Map.hpp.

Map< KEY, DATA >::iterator end ( )
inline
Returns
the end iterator

Definition at line 469 of file Map.hpp.

Map< KEY, DATA >::const_iterator end ( ) const
inline
Returns
the end const_iterator

Definition at line 477 of file Map.hpp.

void erase ( iterator  itr)
inline

Erase the given iterator from the map.

Parameters
[in]itrThe iterator to delete
Precondition
the map must be sorted

Definition at line 130 of file Map.hpp.

bool erase ( const key_type key)
inline

Erase the entry wit given key from the map.

Note
WARNING: This operation will call the costly sort_keys() function if it the internal structure is not sorted.
Parameters
[in]keyThe iterator to delete
Returns
true if element is erased, false if no element was erased

Definition at line 142 of file Map.hpp.

bool exists ( const key_type key)
inline

Check if the given KEY is existing in the Map.

Parameters
[in]keykey to be looked-up
Precondition
Before using exists() the CFMap has to be sorted with sort_keys(). This happens automatically
Returns
flag to know if key exists

Definition at line 374 of file Map.hpp.

bool exists ( const key_type key) const

Check if the given KEY is existing in the Map.

Parameters
[in]keykey to be looked-up
Precondition
before using exists() the CFMap has to be sorted with sort_keys()
Returns
flag to know if key exists

Definition at line 382 of file Map.hpp.

Map< KEY, DATA >::iterator find ( const key_type key)
inline

Find the iterator matching with the given KEY.

Parameters
[in]keykey to be looked-up
Precondition
Before using find() the Map has to be sorted with sort_keys() This happens automatically
Postcondition
If the key is not in the map, the end() iterator is returned.
Returns
the iterator with key and value, the end() iterator is returned if no match is found

Definition at line 335 of file Map.hpp.

Map< KEY, DATA >::const_iterator find ( const key_type key) const
inline

Find the iterator matching with the given KEY.

Parameters
[in]keykey to be looked-up
Precondition
Before using find() the Map has to be sorted with sort_keys() This cannot happen automatically in this const version
Postcondition
If the key is not in the map, the end() iterator is returned.
Returns
the iterator with key and value, the end() iterator is returned if no match is found

Definition at line 355 of file Map.hpp.

std::pair< typename Map< KEY, DATA >::iterator, bool > insert ( const value_type v)
inline

Insert pair the same way a std::map would.

Note
WARNING: this will cause a costly std::sort on the internal structure if sorting did not happen yet.
Parameters
[in]vstd::pair<KEY,DATA> type to
Returns
a pair, with its member pair::first set to an iterator pointing to either the newly inserted element or to the element that already had its same value in the map. The pair::second element in the pair is set to true if a new element was inserted or false if an element with the same value existed.
Postcondition
a new std::pair<KEY, DATA> will be created and pushed back in the map
the capacity of the map will increase only if the memory hasn't been reserved properly at start up.

Definition at line 317 of file Map.hpp.

Map< KEY, DATA >::data_type & operator[] ( const key_type key)
inline

Overloading of the operator"[]" for assignment AND insertion.

Note
WARNING: This procedure will call the costly sort_keys() if the map is not sorted
Parameters
[in]keyThe key to look for. If the key is not found, it is inserted using push_back().
Returns
modifiable data. In case the key did not exist, this will assign the newly created data.

Definition at line 414 of file Map.hpp.

const Map< KEY, DATA >::data_type & operator[] ( const key_type key) const
inline

Overloading of the operator"[]" for assignment AND insertion.

Note
WARNING: This procedure will call the costly sort_keys() if the map is not sorted
Parameters
[in]keyThe key to look for. If the key is not found, it is inserted using push_back().
Returns
non-modifiable data for the given key

Definition at line 428 of file Map.hpp.

Uint push_back ( const key_type key,
const data_type data 
)
inline

Insert pair without any checks if it is already present.

This is the recommended way to add entries to the map, if you are sure that no entries will be duplicated

Parameters
[in]keynew key to be inserted
[in]datanew data to be inserted, corresponding to the given key
Postcondition
a new std::pair<KEY, DATA> will be created and pushed back in the map
the capacity of the map will increase only if the memory hasn't been reserved properly at start up.

Definition at line 307 of file Map.hpp.

void reserve ( size_t  max_size)
inline

Reserve memory.

Parameters
[in]max_sizeof the map to be set before starting inserting pairs in the map
Postcondition
the memory corresponding to the given size will be reserved for the future insertions

Definition at line 285 of file Map.hpp.

size_t size ( ) const

Get the number of pairs already inserted.

Definition at line 406 of file Map.hpp.

void sort_keys ( )

Sort all the pairs in the map by key.

Definition at line 438 of file Map.hpp.

static std::string type_name ( )
inlinestatic

Get the class name.

Definition at line 72 of file Map.hpp.

bool unique_key ( const value_type val1,
const value_type val2 
)
inlinestaticprivate

Helper function to discover if two map entries have the same key

Parameters
[in]val1One of the two entries to compare the key of
[in]val2One of the two entries to compare the key of
Returns
true if duplicate keys are found

Definition at line 485 of file Map.hpp.

Member Data Documentation

bool m_sorted
private

Keeps track of the validity of the map if a key has been inserted and the map has not yet been sorted, then it this will be false

Definition at line 275 of file Map.hpp.

std::vector<value_type> m_vectorMap
private

storage of the inserted data

Definition at line 278 of file Map.hpp.


The documentation for this class was generated from the following file:
Send comments to:
COOLFluiD Web Admin