16#ifndef __albaTimeMap_h
17#define __albaTimeMap_h
52 typedef std::map<albaTimeStamp, albaAutoPointer<T> >
TimeMap;
53 typedef std::pair<albaTimeStamp, albaAutoPointer<T> >
mmuTimePair;
157 virtual void Print(std::ostream& os,
const int tabs=0)
const;
192 if (this->GetNumberOfItems()>0)
195 assert(m_TimeMap.rbegin()->second);
197 m->SetTimeStamp(m_TimeMap.rbegin()->first+1);
212 if (!m_ItemTypeName.IsEmpty())
214 assert(m->IsA(m_ItemTypeName));
215 if (!m->IsA(m_ItemTypeName))
217 albaErrorMacro(
"Unsupported Item type \""<<m->GetTypeName()<<
"\", allowed type is \""<<m_ItemTypeName<<
"\": cannot Append item!");
221 m_TimeMap.insert(m_TimeMap.end(),mmuTimePair(m->GetTimeStamp(),m));
231 if (!m_ItemTypeName.IsEmpty())
233 assert(m->IsA(m_ItemTypeName));
234 if (!m->IsA(m_ItemTypeName))
236 albaErrorMacro(
"Unsupported Item type \""<<m->GetTypeName()<<
"\", allowed type is \""<<m_ItemTypeName<<
"\": cannot Prepend item!");
240 m_TimeMap.insert(m_TimeMap.begin(),mmuTimePair(m->GetTimeStamp(),m));
249 if (!m_ItemTypeName.IsEmpty())
251 assert(m->IsA(m_ItemTypeName));
252 if (!m->IsA(m_ItemTypeName))
254 albaErrorMacro(
"Unsupported Item type \""<<m->GetTypeName()<<
"\", allowed type is \""<<m_ItemTypeName<<
"\": cannot Insert item!");
259 m_TimeMap[m->GetTimeStamp()]=m;
269 if (m_TimeMap.size()>0)
271 tbounds[0]=m_TimeMap.begin()->first;
272 tbounds[1]=m_TimeMap.rbegin()->first;
290 kframes.push_back(it->first);
302 for (it=o->
Begin();it!=o->
End();it++)
305 T *new_item=m->NewInstance();
307 AppendItem(new_item);
325 for (it=m_TimeMap.begin(),it2=o->
m_TimeMap.begin();it!=m_TimeMap.end();it++,it2++)
352 if (it!=m_TimeMap.end())
376 if (range.first!=m_TimeMap.end())
378 if (range.second!=m_TimeMap.end())
380 if (fabs(range.first->first-t)>fabs(range.second->first-t))
385 else if (range.second!=m_TimeMap.end())
390 return --range.second;
399 if (m_TimeMap.size()>0)
402 if (it==m_TimeMap.end()||it!=m_TimeMap.begin()&&it->first>t)
409 return m_TimeMap.end();
420 return m_TimeMap.find(t);
429 return m_TimeMap.find(m->GetTimeStamp());
438 os << indent <<
"Number of Items:"<<GetNumberOfItems()<<
"\n";
440 os << indent <<
"Time Stamps: {";
441 GetTimeStamps(tvector);
442 for (
unsigned int i=0;i<tvector.size();i++)
457 T *m=GetItemByIndex(idx);
458 if (m)
return m->GetTimeStamp();
467 if ((
unsigned int)idx<m_TimeMap.size() && idx>=0)
470 std::advance(it,idx);
474 return m_TimeMap.end();
483 return it!=m_TimeMap.end()?std::distance(m_TimeMap.begin(),it):-1;
492 return (it!=m_TimeMap.end())?it->second:NULL;
501 return (it!=m_TimeMap.end())?it->second:NULL;
509 return (it!=m_TimeMap.end())?it->second:NULL;
517 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.
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.
virtual void AppendItem(T *m)
Insert an item to the vector trying to append it, anyway the array is kept sorted.
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
albaTimeMap< T >::TimeMap::iterator FindItem(albaTimeStamp t)
Find the item with the timestamp==t.
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.
int RemoveItem(int idx)
Remove an item given its index.
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
virtual void AppendAndSetItem(T *m)
append item setting its timestamp to the highest one + 1
virtual void RemoveItem(typename albaTimeMap< T >::TimeMap::iterator it)
Remove an item given its iterator.
virtual void InsertItem(T *m)
Set the item for a specified time.
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.
virtual void RemoveAllItems()
Remove all the items.
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
virtual void PrependItem(T *m)
Insert an item to the vector trying to prepend it, anyway the array is kept sorted.
class acting as an interface for timestamped objects This object simply defines few methods for manag...