16#ifndef __albaTimeMap_h
17#define __albaTimeMap_h
51 typedef std::map<albaTimeStamp, albaAutoPointer<T> >
TimeMap;
52 typedef std::pair<albaTimeStamp, albaAutoPointer<T> >
mmuTimePair;
69 virtual void AppendItem(T *m);
72 virtual void AppendAndSetItem(T *m);
77 virtual void PrependItem(T *m);
87 virtual void InsertItem(T *m);
93 int RemoveItem(
int idx);
96 virtual void RemoveAllItems();
154 T *GetItemByIndex(
int idx);
156 virtual void Print(std::ostream& os,
const int tabs=0)
const;
189 if (this->GetNumberOfItems()>0)
192 assert(m_TimeMap.rbegin()->second);
194 m->SetTimeStamp(m_TimeMap.rbegin()->first+1);
209 if (!m_ItemTypeName.IsEmpty())
211 assert(m->IsA(m_ItemTypeName));
212 if (!m->IsA(m_ItemTypeName))
214 albaErrorMacro(
"Unsupported Item type \""<<m->GetTypeName()<<
"\", allowed type is \""<<m_ItemTypeName<<
"\": cannot Append item!");
218 m_TimeMap.insert(m_TimeMap.end(),
mmuTimePair(m->GetTimeStamp(),m));
228 if (!m_ItemTypeName.IsEmpty())
230 assert(m->IsA(m_ItemTypeName));
231 if (!m->IsA(m_ItemTypeName))
233 albaErrorMacro(
"Unsupported Item type \""<<m->GetTypeName()<<
"\", allowed type is \""<<m_ItemTypeName<<
"\": cannot Prepend item!");
237 m_TimeMap.insert(m_TimeMap.begin(),
mmuTimePair(m->GetTimeStamp(),m));
246 if (!m_ItemTypeName.IsEmpty())
248 assert(m->IsA(m_ItemTypeName));
249 if (!m->IsA(m_ItemTypeName))
251 albaErrorMacro(
"Unsupported Item type \""<<m->GetTypeName()<<
"\", allowed type is \""<<m_ItemTypeName<<
"\": cannot Insert item!");
256 m_TimeMap[m->GetTimeStamp()]=m;
266 if (m_TimeMap.size()>0)
268 tbounds[0]=m_TimeMap.begin()->first;
269 tbounds[1]=m_TimeMap.rbegin()->first;
287 kframes.push_back(it->first);
299 for (it=o->
Begin();it!=o->
End();it++)
302 T *new_item=m->NewInstance();
304 AppendItem(new_item);
322 for (it=m_TimeMap.begin(),it2=o->
m_TimeMap.begin();it!=m_TimeMap.end();it++,it2++)
349 if (it!=m_TimeMap.end())
373 if (range.first!=m_TimeMap.end())
375 if (range.second!=m_TimeMap.end())
377 if (fabs(range.first->first-t)>fabs(range.second->first-t))
382 else if (range.second!=m_TimeMap.end())
387 return --range.second;
396 if (m_TimeMap.size()>0)
399 if (it==m_TimeMap.end()||it!=m_TimeMap.begin()&&it->first>t)
406 return m_TimeMap.end();
417 return m_TimeMap.find(t);
426 return m_TimeMap.find(m->GetTimeStamp());
435 os << indent <<
"Number of Items:"<<GetNumberOfItems()<<
"\n";
437 os << indent <<
"Time Stamps: {";
438 GetTimeStamps(tvector);
439 for (
unsigned int i=0;i<tvector.size();i++)
454 T *m=GetItemByIndex(idx);
455 if (m)
return m->GetTimeStamp();
464 if ((
unsigned int)idx<m_TimeMap.size() && idx>=0)
467 std::advance(it,idx);
471 return m_TimeMap.end();
480 return it!=m_TimeMap.end()?std::distance(m_TimeMap.begin(),it):-1;
489 return (it!=m_TimeMap.end())?it->second:NULL;
498 return (it!=m_TimeMap.end())?it->second:NULL;
506 return (it!=m_TimeMap.end())?it->second:NULL;
514 return (it!=m_TimeMap.end())?it->second:NULL;
#define albaErrorMacro(x)
Macro for printing Error messages in log area.
long albaID
type for IDs inside ALBA
double albaTimeStamp
type for time varying data timestamps (not for pipelines timestamps!)
std::vector< albaTimeStamp > mmuTimeVector
std::vector< albaTimeStamp > mmuTimeVector
albaIndent - a simple class to control print indentation.
Abstract superclass for all ALBA classes implementing RTTI APIs.
virtual void Print(std::ostream &os, const int indent=0) const
print debug information for this object
albaString - performs common string operations on c-strings.
a dynamic associative sorted array of timestamped objects indexed by their "timestamp".
virtual void RemoveAllItems()
Remove all the items.
bool Equals(albaTimeMap *vmat)
Compare two different arrays for equality.
TimeMap m_TimeMap
the set storing the datasets
virtual void Print(std::ostream &os, const int tabs=0) const
print debug information for this object
virtual void PrependItem(T *m)
Insert an item to the vector trying to prepend it, anyway the array is kept sorted.
virtual void RemoveItem(typename albaTimeMap< T >::TimeMap::iterator it)
Remove an item given its iterator.
void GetTimeBounds(albaTimeStamp tbounds[2])
Set/Get the Current time for this object.
int GetNumberOfItems() const
Return the number of ITEMS stored in this object.
albaTimeMap< T >::TimeMap::iterator Last()
albaTimeMap(const albaTimeMap< T > &)
void GetTimeStamps(mmuTimeVector &kframes) const
Return the list of timestamp of the key matrixes in the given vector.
albaTimeMap< T >::TimeMap::iterator End()
std::pair< albaTimeStamp, albaAutoPointer< T > > mmuTimePair
albaTimeStamp GetItemTime(int idx)
Return the timestamp of the i-th item.
albaString m_ItemTypeName
the name of the item type accepted by this container
void DeepCopy(albaTimeMap *vitem)
Copy data from another array.
albaTimeMap< T >::TimeMap::iterator FindItemByIndex(int idx)
return iterator of item with given index
T * GetItem(albaTimeStamp t)
find and return item corresponding to timestamp t.
albaTimeMap< T >::TimeMap::iterator Begin()
void SetItemTypeName(const char *tname)
set the TypeName of the kind of item accepted by this container
virtual void AppendAndSetItem(T *m)
append item setting its timestamp to the highest one + 1
T * GetNearestItem(albaTimeStamp t)
Return the pointer to the item with timestamp nearest the given one.
albaTimeMap< T >::TimeMap::iterator FindItem(T *m)
Find an item index given its pointer.
virtual void AppendItem(T *m)
Insert an item to the vector trying to append it, anyway the array is kept sorted.
T * GetItemByIndex(int idx)
return the item with given its order index.
void operator=(const albaTimeMap< T > &)
T * GetItemBefore(albaTimeStamp t)
Return the pointer to the item with timestamp nearest the given one.
const char * GetItemTypeName()
albaTimeMap< T >::TimeMap::iterator FindNearestItem(albaTimeStamp t)
Find the item with the timestamp nearest to t.
virtual void InsertItem(T *m)
Set the item for a specified time.
albaID FindItemIndex(albaTimeStamp t)
return index of the given item.
albaTimeMap< T >::TimeMap::iterator FindItemBefore(albaTimeStamp t)
Find the item with timestamp <=t.
std::map< albaTimeStamp, albaAutoPointer< T > > TimeMap
class acting as an interface for timestamped objects This object simply defines few methods for manag...