FlyWeightLists< ValueType, UniqueTag > Class Template Reference

#include <FlyWeight.h>

Inheritance diagram for FlyWeightLists< ValueType, UniqueTag >:
TObject

List of all members.

Public Types

typedef int Proxy_t
typedef std::map< ValueType,
Proxy_t
ValueToProxyMap
typedef std::vector< ValueType > ProxyToValueMap

Public Member Functions

 FlyWeightLists ()
bool empty () const
FlyWeight

A generic flyweight to store relatively bulky objects that are massively re-used, such as the source IDs in each TAP / TDP.

Objects such as TAPs and TDPs often contain largely repeated data such as the source ID for all pulses coming from the same algorithm applied to the same detector channel. To reduce the redundancy and therefore save memory and some processing time, this class implements a simple version of the flyweight pattern, which replaces each different value with an int, but provides a similar interface to the object that it wraps. When we want to store a new value, it is searched for in the ProxyToValueMap and the index identifying where it is is saved is used instead. If the value has not been used already, it is added to the list of values

Template Parameters:
ValueType The type of value this flyweight contains
UniqueTag An optional template parameter to make sure the flyweight is unique, such as to separate the flyweight for TAPs from TDPs, even though the ValueType is the same


int GetProxy (const ValueType &v)
const ValueType & GetValue (const Proxy_t &v)
void DumpTable () const

Private Member Functions

 ClassDef (FlyWeightLists, 1)

Private Attributes

ProxyToValueMap sProxyToVals
ValueToProxyMap sValsToProxies

Detailed Description

template<typename ValueType, typename UniqueTag = int>
class FlyWeightLists< ValueType, UniqueTag >

Definition at line 13 of file FlyWeight.h.


Member Typedef Documentation

template<typename ValueType, typename UniqueTag = int>
typedef int FlyWeightLists< ValueType, UniqueTag >::Proxy_t

Definition at line 15 of file FlyWeight.h.

template<typename ValueType, typename UniqueTag = int>
typedef std::vector<ValueType> FlyWeightLists< ValueType, UniqueTag >::ProxyToValueMap

Definition at line 18 of file FlyWeight.h.

template<typename ValueType, typename UniqueTag = int>
typedef std::map<ValueType,Proxy_t> FlyWeightLists< ValueType, UniqueTag >::ValueToProxyMap

Definition at line 17 of file FlyWeight.h.


Constructor & Destructor Documentation

template<typename ValueType, typename UniqueTag = int>
FlyWeightLists< ValueType, UniqueTag >::FlyWeightLists (  )  [inline]

Definition at line 15 of file FlyWeight.h.

00015 {};


Member Function Documentation

template<typename ValueType, typename UniqueTag = int>
FlyWeightLists< ValueType, UniqueTag >::ClassDef ( FlyWeightLists< ValueType, UniqueTag >  ,
 
) [private]
template<typename ValueType , typename UniqueTag >
void FlyWeightLists< ValueType, UniqueTag >::DumpTable (  )  const [inline]

Definition at line 154 of file FlyWeight.h.

References FlyWeightLists< ValueType, UniqueTag >::sProxyToVals, and FlyWeightLists< ValueType, UniqueTag >::sValsToProxies.

00154                                                                {
00155     std::cout<<"Proxy | Value | Proxy"<<std::endl;
00156     for(unsigned i=0;i<sProxyToVals.size();i++){
00157         std::cout<<i<<" | "<<sProxyToVals[i]<<" | "<<sValsToProxies.find(sProxyToVals[i])->second<<std::endl;
00158     }
00159 }

template<typename ValueType, typename UniqueTag = int>
bool FlyWeightLists< ValueType, UniqueTag >::empty (  )  const [inline]

Definition at line 23 of file FlyWeight.h.

00023 {return sProxyToVals.empty();}

template<typename ValueType, typename UniqueTag >
int FlyWeightLists< ValueType, UniqueTag >::GetProxy ( const ValueType &  v  )  [inline]

Definition at line 140 of file FlyWeight.h.

References FlyWeightLists< ValueType, UniqueTag >::sProxyToVals, and FlyWeightLists< ValueType, UniqueTag >::sValsToProxies.

00140                                                                           {
00141     // Is this proxy already contained in the maps
00142     typename ValueToProxyMap::const_iterator it=sValsToProxies.find(v);
00143     if(it!=sValsToProxies.end()){
00144         return it->second;
00145     } 
00146     // if it's a new kind, add the source to the hash table
00147     int proxy=sValsToProxies.size();
00148     sValsToProxies[v]=proxy;
00149     sProxyToVals.push_back(v);
00150     return proxy;
00151 }

template<typename ValueType , typename UniqueTag >
const ValueType & FlyWeightLists< ValueType, UniqueTag >::GetValue ( const Proxy_t v  )  [inline]

Definition at line 134 of file FlyWeight.h.

References FlyWeightLists< ValueType, UniqueTag >::sProxyToVals.

00135                          {
00136     return sProxyToVals.at(v);
00137 }


Member Data Documentation

template<typename ValueType, typename UniqueTag = int>
ProxyToValueMap FlyWeightLists< ValueType, UniqueTag >::sProxyToVals [private]
template<typename ValueType, typename UniqueTag = int>
ValueToProxyMap FlyWeightLists< ValueType, UniqueTag >::sValsToProxies [private]

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

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1