Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

TimeMap< Entry > Class Template Reference

A time map provides a means of addressing time entries consistently over the 0 to 1 time range for which its defined. More...

#include <time_map.h>

List of all members.

Public Member Functions

virtual ~TimeMap ()
void Clear ()
void FinishedWith (Entry *entry)
bool RoughlyEquals (double x, double y)
Entry * Get (double position)
Entry * SetEditable (double position, bool editable)
Entry * GotoNextKey (double position)
Entry * GotoPreviousKey (double position)
double GetFirst ()
double GetLast ()
double GetNext (double position)
double GetPrevious (double position)
bool IsKeyFrame (double position)
void Invert ()

Private Attributes

map< double, Entry * > key_frames


Detailed Description

template<typename Entry>
class TimeMap< Entry >

A time map provides a means of addressing time entries consistently over the 0 to 1 time range for which its defined.

Definition at line 183 of file time_map.h.


Constructor & Destructor Documentation

template<typename Entry>
virtual TimeMap< Entry >::~TimeMap  )  [inline, virtual]
 

Definition at line 189 of file time_map.h.

00189 { }


Member Function Documentation

template<typename Entry>
void TimeMap< Entry >::Clear  )  [inline]
 

Definition at line 191 of file time_map.h.

References TimeMap< Entry >::key_frames.

00192         {
00193             key_frames.erase( key_frames.begin( ), key_frames.end( ) );
00194         }

template<typename Entry>
void TimeMap< Entry >::FinishedWith Entry *  entry  )  [inline]
 

Definition at line 196 of file time_map.h.

Referenced by TimeMap< Entry >::SetEditable().

00197         {
00198             if ( !entry->IsEditable( ) )
00199                 delete entry;
00200         }

template<typename Entry>
Entry* TimeMap< Entry >::Get double  position  )  [inline]
 

Definition at line 207 of file time_map.h.

References TimeMap< Entry >::GetFirst(), TimeMap< Entry >::GetNext(), TimeMap< Entry >::GetPrevious(), TimeMap< Entry >::IsKeyFrame(), and TimeMap< Entry >::key_frames.

Referenced by TimeMap< Entry >::GotoNextKey(), TimeMap< Entry >::GotoPreviousKey(), and TimeMap< Entry >::SetEditable().

00208         {
00209             Entry *current = NULL;
00210             position = (double)( rint( position * 1000000 ) / 1000000 );
00211 
00212             if ( key_frames.size() == 0 )
00213             {
00214                 current = new Entry();
00215                 current->SetPosition( position );
00216                 current->SetEditable( false );
00217             }
00218             else if ( key_frames.size() == 1 )
00219             {
00220                 double first_key = GetFirst( );
00221                 Entry *ante = key_frames[ first_key ];
00222 
00223                 if ( position != first_key )
00224                     current = new Entry( position, *ante );
00225                 else
00226                     current = ante;
00227             }
00228             else 
00229             {
00230                 double post_key = GetNext( position );
00231                 double ante_key = GetPrevious( position );
00232                 bool frame_key = IsKeyFrame( position );
00233 
00234                 if ( frame_key )
00235                 {
00236                     current = key_frames[ position ];
00237                 }
00238                 else
00239                 {
00240                     Entry *ante = key_frames[ ante_key ];
00241 
00242                     // We may now be at the end of the map
00243                     if ( post_key == ante_key )
00244                     {
00245                         current = new Entry( position, *ante );
00246                     }
00247                     else
00248                     {
00249                         Entry *post = key_frames[ post_key ];
00250                         current = ante->Get( position, post );
00251                     }
00252                 }
00253             }
00254 
00255             return current;
00256         }

template<typename Entry>
double TimeMap< Entry >::GetFirst  )  [inline]
 

Definition at line 287 of file time_map.h.

References TimeMap< Entry >::key_frames.

Referenced by TimeMap< Entry >::Get().

00288         {
00289             typename map< double, Entry * >::iterator it = key_frames.begin();
00290             if ( it == key_frames.end() )
00291                 return 0;
00292             else
00293                 return it->first;
00294         }

template<typename Entry>
double TimeMap< Entry >::GetLast  )  [inline]
 

Definition at line 296 of file time_map.h.

References TimeMap< Entry >::key_frames.

00297         {
00298             typename map< double, Entry * >::iterator it = key_frames.end();
00299             if ( key_frames.size() == 0 )
00300                 return 0;
00301             else
00302                 return ( -- it )->first;
00303         }

template<typename Entry>
double TimeMap< Entry >::GetNext double  position  )  [inline]
 

Definition at line 305 of file time_map.h.

References TimeMap< Entry >::key_frames.

Referenced by TimeMap< Entry >::Get(), and TimeMap< Entry >::GotoNextKey().

00306         {
00307             double ret_val = 0;
00308             if ( key_frames.size() >= 1 )
00309             {
00310                 typename map< double, Entry * >::iterator it = key_frames.begin();
00311                 for ( ; ret_val <= position && it != key_frames.end(); it ++ )
00312                     ret_val = it->first;
00313 /*              if ( it != key_frames.end() )
00314                 {
00315                     ++it;
00316                     ret_val = it->first;
00317                 }*/
00318             }
00319             return ret_val;
00320         }

template<typename Entry>
double TimeMap< Entry >::GetPrevious double  position  )  [inline]
 

Definition at line 322 of file time_map.h.

References TimeMap< Entry >::key_frames.

Referenced by TimeMap< Entry >::Get(), and TimeMap< Entry >::GotoPreviousKey().

00323         {
00324             double ret_val = 0;
00325             if ( key_frames.size() >= 1 )
00326             {
00327                 typename map< double, Entry * >::iterator it = key_frames.begin();
00328                 for ( ; it != key_frames.end() && it->first < position; it ++ )
00329                     ret_val = it->first;
00330 /*              if ( it != key_frames.begin() )
00331                 {
00332                     --it;
00333                     ret_val = it->first;
00334                 }*/
00335             }
00336             return ret_val;
00337         }

template<typename Entry>
Entry* TimeMap< Entry >::GotoNextKey double  position  )  [inline]
 

Definition at line 277 of file time_map.h.

References TimeMap< Entry >::Get(), and TimeMap< Entry >::GetNext().

00278         {
00279             return Get( GetNext( position + 0.000001 ) );
00280         }

template<typename Entry>
Entry* TimeMap< Entry >::GotoPreviousKey double  position  )  [inline]
 

Definition at line 282 of file time_map.h.

References TimeMap< Entry >::Get(), and TimeMap< Entry >::GetPrevious().

00283         {
00284             return Get( GetPrevious( position - 0.000001 ) );
00285         }

template<typename Entry>
void TimeMap< Entry >::Invert  )  [inline]
 

Definition at line 353 of file time_map.h.

References TimeMap< Entry >::key_frames.

00354         {
00355             map < double, Entry * > temp_frames;
00356             if ( key_frames.size() >= 1 )
00357             {
00358                 typename map< double, Entry * >::iterator it = key_frames.begin();
00359                 for ( ; it != key_frames.end(); it ++ )
00360                 {
00361                     it->second->SetPosition( 0.999999 - it->first );
00362                     temp_frames[ 0.999999 - it->first ] = it->second;
00363                 }
00364             }
00365 
00366             key_frames = temp_frames;
00367         }

template<typename Entry>
bool TimeMap< Entry >::IsKeyFrame double  position  )  [inline]
 

Definition at line 339 of file time_map.h.

References TimeMap< Entry >::key_frames.

Referenced by TimeMap< Entry >::Get().

00340         {
00341             if ( key_frames.size() >= 1 )
00342             {
00343                 typename map< double, Entry * >::iterator it = key_frames.begin();
00344                 for ( ; it != key_frames.end() && it->first <= position; it ++ )
00345                 {
00346                     if ( position == it->first )
00347                         return true;
00348                 }
00349             }
00350             return false;
00351         }

template<typename Entry>
bool TimeMap< Entry >::RoughlyEquals double  x,
double  y
[inline]
 

Definition at line 202 of file time_map.h.

00203         {
00204             return x == y;
00205         }

template<typename Entry>
Entry* TimeMap< Entry >::SetEditable double  position,
bool  editable
[inline]
 

Definition at line 258 of file time_map.h.

References TimeMap< Entry >::FinishedWith(), TimeMap< Entry >::Get(), and TimeMap< Entry >::key_frames.

00259         {
00260             Entry *entry = Get( position );
00261             position = (double)( rint( position * 1000000 ) / 1000000 );
00262 
00263             if ( entry->IsEditable() != editable )
00264             {
00265                 if ( entry->IsEditable() )
00266                     key_frames.erase( position );
00267                 else
00268                     key_frames[ position ] = entry;
00269                 entry->SetEditable( editable );
00270             }
00271 
00272             FinishedWith( entry );
00273 
00274             return Get( position );
00275         }


Member Data Documentation

template<typename Entry>
map< double, Entry * > TimeMap< Entry >::key_frames [private]
 

Definition at line 186 of file time_map.h.

Referenced by TimeMap< Entry >::Clear(), TimeMap< Entry >::Get(), TimeMap< Entry >::GetFirst(), TimeMap< Entry >::GetLast(), TimeMap< Entry >::GetNext(), TimeMap< Entry >::GetPrevious(), TimeMap< Entry >::Invert(), TimeMap< Entry >::IsKeyFrame(), and TimeMap< Entry >::SetEditable().


The documentation for this class was generated from the following file:
Generated on Sun Mar 11 22:13:25 2007 for Kino by  doxygen 1.4.2