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

SMIL::Time Class Reference

#include <smiltime.h>

Inheritance diagram for SMIL::Time:

Inheritance graph
[legend]
List of all members.

Public Types

enum  TimeType {
  SMIL_TIME_INDEFINITE = 0, SMIL_TIME_OFFSET, SMIL_TIME_SYNC_BASED, SMIL_TIME_EVENT_BASED,
  SMIL_TIME_WALLCLOCK, SMIL_TIME_MEDIA_MARKER, SMIL_TIME_REPEAT, SMIL_TIME_ACCESSKEY
}
enum  TimeFormat {
  TIME_FORMAT_NONE = 0, TIME_FORMAT_FRAMES, TIME_FORMAT_SMPTE, TIME_FORMAT_CLOCK,
  TIME_FORMAT_MS, TIME_FORMAT_S, TIME_FORMAT_MIN, TIME_FORMAT_H
}

Public Member Functions

 Time ()
 Time (long time)
 Time (string time)
virtual ~Time ()
virtual void parseTimeValue (string time)
long getTimeValue ()
TimeType getTimeType ()
long getOffset ()
bool operator< (Time &time)
bool operator== (Time &time)
bool operator> (Time &time)
bool isResolved ()
long getResolvedOffset ()
bool isNegative ()
bool isIndefinite ()
virtual string toString (TimeFormat format=TIME_FORMAT_CLOCK)
virtual string serialise ()

Protected Member Functions

long parseClockValue (string time)

Protected Attributes

long timeValue
long offset
bool indefinite
bool resolved
bool syncbaseBegin
TimeType timeType

Private Member Functions

void setTimeValue (Time &source)

Member Enumeration Documentation

enum SMIL::Time::TimeFormat
 

Enumeration values:
TIME_FORMAT_NONE 
TIME_FORMAT_FRAMES 
TIME_FORMAT_SMPTE 
TIME_FORMAT_CLOCK 
TIME_FORMAT_MS 
TIME_FORMAT_S 
TIME_FORMAT_MIN 
TIME_FORMAT_H 

Definition at line 45 of file smiltime.h.

enum SMIL::Time::TimeType
 

Enumeration values:
SMIL_TIME_INDEFINITE 
SMIL_TIME_OFFSET 
SMIL_TIME_SYNC_BASED 
SMIL_TIME_EVENT_BASED 
SMIL_TIME_WALLCLOCK 
SMIL_TIME_MEDIA_MARKER 
SMIL_TIME_REPEAT 
SMIL_TIME_ACCESSKEY 

Definition at line 34 of file smiltime.h.

00034                  {
00035         SMIL_TIME_INDEFINITE = 0,
00036         SMIL_TIME_OFFSET,
00037         SMIL_TIME_SYNC_BASED,    // not implemented
00038         SMIL_TIME_EVENT_BASED,    // not implemented
00039         SMIL_TIME_WALLCLOCK,    // not implemented
00040         SMIL_TIME_MEDIA_MARKER,    // not implemented
00041         SMIL_TIME_REPEAT,     // not implemented
00042         SMIL_TIME_ACCESSKEY,    //not implemented
00043     } TimeType;


Constructor & Destructor Documentation

SMIL::Time::Time  ) 
 

Definition at line 40 of file smiltime.cc.

References indefinite, resolved, SMIL_TIME_INDEFINITE, and timeType.

Referenced by Time().

00041 {
00042     Time( 0L );
00043     indefinite = true;
00044     timeType = SMIL_TIME_INDEFINITE;
00045     resolved = true;
00046 }

SMIL::Time::Time long  time  ) 
 

Definition at line 49 of file smiltime.cc.

00049                       :
00050     timeValue( time ), 
00051     offset( 0 ),
00052     indefinite( false ), 
00053     resolved( true ), 
00054     syncbaseBegin( false ),
00055     timeType( SMIL_TIME_OFFSET )
00056 {
00057 }

SMIL::Time::Time string  time  ) 
 

Definition at line 60 of file smiltime.cc.

References parseTimeValue(), and Time().

00061 {
00062     Time( 0L );
00063     parseTimeValue( time );
00064 }

virtual SMIL::Time::~Time  )  [inline, virtual]
 

Definition at line 70 of file smiltime.h.

00071     {}


Member Function Documentation

long SMIL::Time::getOffset  )  [inline]
 

Definition at line 83 of file smiltime.h.

References offset.

00084     {
00085         return offset;
00086     }

long SMIL::Time::getResolvedOffset  ) 
 

Definition at line 254 of file smiltime.cc.

References offset, resolved, and timeValue.

Referenced by SMIL::MediaClippingTime::getFrames(), isNegative(), operator==(), operator>(), SMIL::MediaClippingTime::toString(), and toString().

00255 {
00256     return ( resolved ? ( timeValue + offset ) : 0 );
00257 }

TimeType SMIL::Time::getTimeType  )  [inline]
 

Definition at line 79 of file smiltime.h.

References timeType.

00080     {
00081         return timeType;
00082     }

long SMIL::Time::getTimeValue  )  [inline]
 

Definition at line 75 of file smiltime.h.

References timeValue.

Referenced by setTimeValue().

00076     {
00077         return timeValue;
00078     }

bool SMIL::Time::isIndefinite  )  [inline]
 

Definition at line 97 of file smiltime.h.

References indefinite.

Referenced by operator==(), operator>(), and setTimeValue().

00098     {
00099         return indefinite;
00100     }

bool SMIL::Time::isNegative  ) 
 

Definition at line 259 of file smiltime.cc.

References getResolvedOffset(), indefinite, and resolved.

00260 {
00261     return ( resolved && !indefinite && ( getResolvedOffset() < 0 ) );
00262 }

bool SMIL::Time::isResolved  )  [inline]
 

Definition at line 91 of file smiltime.h.

References resolved.

Referenced by operator>(), and setTimeValue().

00092     {
00093         return resolved;
00094     }

bool SMIL::Time::operator< Time time  ) 
 

Definition at line 265 of file smiltime.cc.

00266 {
00267     return !( ( *this > time ) || ( *this == time ) );
00268 }

bool SMIL::Time::operator== Time time  ) 
 

Definition at line 271 of file smiltime.cc.

References getResolvedOffset(), and isIndefinite().

00272 {
00273     return (
00274                ( this->isIndefinite() && time.isIndefinite() ) ||
00275                ( this->getResolvedOffset() == time.getResolvedOffset() )
00276            );
00277 }

bool SMIL::Time::operator> Time time  ) 
 

Definition at line 280 of file smiltime.cc.

References getResolvedOffset(), indefinite, isIndefinite(), isResolved(), and resolved.

00281 {
00282     return (
00283                ( !resolved ) ||
00284                ( indefinite && time.isResolved() && !time.isIndefinite() ) ||
00285                ( resolved && time.isResolved() && this->getResolvedOffset() > time.getResolvedOffset() )
00286            );
00287 }

long SMIL::Time::parseClockValue string  time  )  [protected]
 

Definition at line 192 of file smiltime.cc.

References StringUtils::ends(), and SMIL::getFraction().

Referenced by parseTimeValue().

00193 {
00194     long total = 0;
00195     string hours;
00196     string minutes;
00197     string seconds;
00198     string milliseconds;
00199     string::size_type pos1, pos2;
00200 
00201     if ( ( pos1 = time.find( ':' ) ) != string::npos )
00202     {
00203         if ( ( pos2 = time.find( ':', pos1 + 1 ) ) != string::npos )
00204         {
00205             //parse Full-clock-value
00206             //cerr << "smil: parsing Full clock value " << time << endl;
00207             hours = time.substr( 0, pos1 );
00208             time = time.substr( pos1 + 1 );
00209             pos1 = pos2 - pos1 - 1;
00210         }
00211         //parse Partial-clock-value
00212         //cerr << "smil: parsing Partial clock value " << time << endl;
00213         if ( ( pos2 = time.find( '.' ) ) != string::npos )
00214         {
00215             milliseconds = time.substr( pos2 + 1, 3 );
00216             time = time.substr( 0, pos2 );
00217         }
00218         minutes = time.substr( 0, pos1 );
00219         seconds = time.substr( pos1 + 1 );
00220     }
00221     else
00222     {
00223         //parse Timecount-value
00224         //cerr << "smil: parsing Timecount value " << time << endl;
00225         if ( StringUtils::ends( time, "h" ) )
00226         {
00227             total = ( long ) ( atof( getFraction( time ).c_str() ) * 3600 );
00228             hours = time;
00229         }
00230         else if ( StringUtils::ends( time, "min" ) )
00231         {
00232             total = ( long ) ( atof( getFraction( time ).c_str() ) * 60 );
00233             minutes = time;
00234         }
00235         else if ( StringUtils::ends( time, "ms" ) )
00236         {
00237             total = ( long ) ( atof( time.c_str() ) + 0.5 );
00238         }
00239         else
00240         {
00241             total = atol( getFraction( time ).c_str() );
00242             seconds = time;
00243         }
00244     }
00245     //cerr << "smil: subtotal = " << total << ", h = " << atol(hours.c_str()) <<
00246     //  ", m = " << atol(minutes.c_str()) << ", s = " << atol(seconds.c_str()) <<
00247     //  ", ms = " << (long) (atof(milliseconds.c_str()) * 1000) << endl;
00248     total += ( atol( hours.c_str() ) * 3600 + atol( minutes.c_str() ) * 60 +
00249                atol( seconds.c_str() ) ) * 1000 + atol( milliseconds.c_str() );
00250     return total;
00251 }

void SMIL::Time::parseTimeValue string  time  )  [virtual]
 

Definition at line 66 of file smiltime.cc.

References StringUtils::begins(), indefinite, offset, parseClockValue(), resolved, SMIL_TIME_ACCESSKEY, SMIL_TIME_EVENT_BASED, SMIL_TIME_INDEFINITE, SMIL_TIME_MEDIA_MARKER, SMIL_TIME_OFFSET, SMIL_TIME_REPEAT, SMIL_TIME_SYNC_BASED, SMIL_TIME_WALLCLOCK, StringUtils::stripWhite(), syncbaseBegin, timeType, and timeValue.

Referenced by SMIL::MediaClippingTime::parseValue(), and Time().

00067 {
00068     time = StringUtils::stripWhite( time );
00069 
00070     resolved = false;
00071 
00072     if ( StringUtils::begins ( time, "indefinite" ) || time.empty() || time.size() == 0 )
00073     {
00074         indefinite = true;
00075         timeType = SMIL_TIME_INDEFINITE;
00076         resolved = true;
00077         //cerr << "smil: this is an indefinite time value" << endl;
00078     }
00079     else if ( time.at( 0 ) == '+' || time.at( 0 ) == '-' )
00080     {
00081         //cerr << "smil: this is an offset time value" << endl;
00082         timeValue = parseClockValue( time.substr( 1 ) );
00083         if ( time.at( 0 ) == '-' )
00084             timeValue *= -1;
00085         timeType = SMIL_TIME_OFFSET;
00086         resolved = true;
00087         indefinite = false;
00088     }
00089     else if ( StringUtils::begins ( time, "wallclock(" ) )
00090     {
00091         //parseWallclockValue(time);
00092         timeType = SMIL_TIME_WALLCLOCK;
00093         resolved = true;
00094         indefinite = false;
00095         //cerr << "smil: this is a wallclock time value" << endl;
00096     }
00097     else if ( StringUtils::begins ( time, "accesskey(" ) )
00098     {
00099         timeType = SMIL_TIME_ACCESSKEY;
00100         //cerr << "smil: this is an accesskey   time value" << endl;
00101     }
00102     else
00103     {
00104         std::ostringstream token;
00105         char c;
00106         string::size_type pos = 0;
00107         string base;
00108         for ( ; pos < time.size(); ++pos )
00109         {
00110             c = time.at( pos );
00111             if ( c == '+' || c == '-' )
00112             {
00113                 string symbol = token.str();
00114                 token.str( string() );
00115                 //cerr << "smil: parsed symbol token '" << symbol << "'" << endl;
00116 
00117                 if ( symbol == string( "begin" ) )
00118                 {
00119                     //cerr << "smil: this is a sync based time value" << endl;
00120                     syncbaseBegin = true;
00121                     timeType = SMIL_TIME_SYNC_BASED;
00122                 }
00123                 else if ( symbol == string( "end" ) )
00124                 {
00125                     //cerr << "smil: this is a sync based time value" << endl;
00126                     syncbaseBegin = false;
00127                     timeType = SMIL_TIME_SYNC_BASED;
00128                 }
00129                 else if ( StringUtils::begins( symbol, "marker(" ) )
00130                 {
00131                     //cerr << "smil: this is a media marker time value" << endl;
00132                     //parseMediaMarkerValue(base, token); // base must not be empty
00133                     timeType = SMIL_TIME_MEDIA_MARKER;
00134                 }
00135                 else if ( StringUtils::begins( symbol, "repeat(" ) )
00136                 {
00137                     //cerr << "smil: this is an event repeat time value" << endl;
00138                     //parseRepeatValue(base, token); // base can be empty := current element
00139                     timeType = SMIL_TIME_REPEAT;
00140                 }
00141                 else
00142                 {
00143                     //cerr << "smil: this is an event based time value" << endl;
00144                     //parseEventValue( base, token ); // base can be empty := current element
00145                     timeType = SMIL_TIME_EVENT_BASED;
00146                 }
00147                 offset = parseClockValue( time.substr( pos + 1 ) );
00148                 if ( c == '-' )
00149                     offset *= -1;
00150                 break;
00151             }
00152             else if ( c == '.' && ( pos == 0 || time.at( pos - 1 ) != '\\' ) )
00153             {
00154                 base = token.str();
00155                 token.str( string() );
00156                 //cerr << "smil: parsed base token '" << base << "'" << endl;
00157             }
00158             else
00159             {
00160                 token << c;
00161             }
00162         }
00163         string remaining = token.str();
00164         //cerr << "smil: parsed remaining token '" << remaining << "'" << endl;
00165         if ( !remaining.empty() )
00166         {
00167             //cerr << "smil: this is an offset time value" << endl;
00168             offset = parseClockValue( time );
00169             timeType = SMIL_TIME_OFFSET;
00170             resolved = true;
00171             indefinite = false;
00172         }
00173     }
00174 }

string SMIL::Time::serialise  )  [virtual]
 

Reimplemented in SMIL::MediaClippingTime.

Definition at line 356 of file smiltime.cc.

References toString().

00357 {
00358     return toString();
00359 }

void SMIL::Time::setTimeValue Time source  )  [private]
 

Definition at line 290 of file smiltime.cc.

References getTimeValue(), indefinite, isIndefinite(), isResolved(), resolved, and timeValue.

00291 {
00292     resolved = source.isResolved();
00293     indefinite = source.isIndefinite();
00294     timeValue = source.getTimeValue();
00295 }

string SMIL::Time::toString TimeFormat  format = TIME_FORMAT_CLOCK  )  [virtual]
 

Reimplemented in SMIL::MediaClippingTime.

Definition at line 298 of file smiltime.cc.

References getResolvedOffset(), indefinite, resolved, TIME_FORMAT_CLOCK, TIME_FORMAT_H, TIME_FORMAT_MIN, TIME_FORMAT_MS, and TIME_FORMAT_S.

Referenced by SMIL::MediaClippingTime::serialise(), serialise(), and SMIL::MediaClippingTime::toString().

00299 {
00300     long ms = getResolvedOffset();
00301     ostringstream str;
00302     
00303     if ( indefinite )
00304     {
00305         str << "indefinite";
00306     }
00307     else if ( !resolved )
00308     {
00309         str << "unresolved";
00310     }
00311     else switch( format )
00312     {
00313         case TIME_FORMAT_CLOCK:
00314         {
00315             int hh = ( ms / 3600000 );
00316             ms -= hh * 3600000;
00317             int mm = ( ms / 60000 );
00318             ms -= mm * 60000;
00319             int ss = ms / 1000;
00320             ms -= ss * 1000;
00321     
00322             str << std::setfill( '0' ) << std::setw( 2 ) << hh << 
00323             ":" << std::setfill( '0' ) << std::setw( 2 ) << mm << 
00324             ":" << std::setfill( '0' ) << std::setw( 2 ) << ss << "." <<
00325             std::setfill( '0' ) << std::setw( 3 ) << ms;
00326             break;
00327         }
00328         case TIME_FORMAT_MS:
00329             str << ms << "ms";
00330             break;
00331         
00332         case TIME_FORMAT_S:
00333             str << ( ms / 1000 ) << "." << 
00334             std::setfill( '0' ) << std::setw( 3 ) << ( ms % 1000 );
00335             break;
00336         
00337         case TIME_FORMAT_MIN:
00338             str << ( ms / 60000 ) << "." << 
00339                 std::setfill( '0' ) << std::setw( 4 ) << 
00340                 floor( ( float )( ms % 60000 ) / 6 + 0.5 ) << "min";
00341             break;
00342         
00343         case TIME_FORMAT_H:
00344             str << ( ms / 3600000 ) << "." << 
00345                 std::setfill( '0' ) << std::setw( 5 ) << 
00346                 floor( ( float )( ms % 3600000 ) / 36 + 0.5 ) << "h";
00347             break;
00348         
00349         default:
00350             break;
00351     }
00352     return str.str();
00353 
00354 }


Member Data Documentation

bool SMIL::Time::indefinite [protected]
 

Definition at line 61 of file smiltime.h.

Referenced by isIndefinite(), isNegative(), operator>(), SMIL::MediaClippingTime::parseFramesToString(), SMIL::MediaClippingTime::parseSmpteValue(), parseTimeValue(), setTimeValue(), Time(), SMIL::MediaClippingTime::toString(), and toString().

long SMIL::Time::offset [protected]
 

Definition at line 60 of file smiltime.h.

Referenced by getOffset(), getResolvedOffset(), SMIL::MediaClippingTime::parseFramesToString(), parseTimeValue(), and SMIL::MediaClippingTime::parseValueToString().

bool SMIL::Time::resolved [protected]
 

Definition at line 62 of file smiltime.h.

Referenced by getResolvedOffset(), isNegative(), isResolved(), operator>(), SMIL::MediaClippingTime::parseFramesToString(), SMIL::MediaClippingTime::parseSmpteValue(), parseTimeValue(), setTimeValue(), Time(), SMIL::MediaClippingTime::toString(), and toString().

bool SMIL::Time::syncbaseBegin [protected]
 

Definition at line 63 of file smiltime.h.

Referenced by parseTimeValue().

TimeType SMIL::Time::timeType [protected]
 

Definition at line 64 of file smiltime.h.

Referenced by getTimeType(), parseTimeValue(), and Time().

long SMIL::Time::timeValue [protected]
 

Definition at line 59 of file smiltime.h.

Referenced by getResolvedOffset(), getTimeValue(), SMIL::MediaClippingTime::parseFramesToString(), SMIL::MediaClippingTime::parseSmpteValue(), parseTimeValue(), SMIL::MediaClippingTime::parseValueToString(), and setTimeValue().


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