finalcut/src/fobject.h

207 lines
5.0 KiB
C
Raw Normal View History

// File: fobject.h
// Provides: class FObject
//
// Base class
// ══════════
//
// ▕▔▔▔▔▔▔▔▔▔▏
// ▕ FObject ▏
// ▕▁▁▁▁▁▁▁▁▁▏
2015-05-23 13:35:12 +02:00
#ifndef _FOBJECT_H
#define _FOBJECT_H
#include <stdint.h>
2015-05-23 13:35:12 +02:00
#include <sys/time.h> // need for gettimeofday
#include <cstdlib>
#include <list>
#include <vector>
2015-08-22 18:53:52 +02:00
2015-05-23 13:35:12 +02:00
#include "fevent.h"
2015-05-23 13:35:12 +02:00
#define null NULL
typedef unsigned char uChar;
typedef unsigned int uInt;
typedef unsigned long uLong;
typedef uint8_t uInt8;
typedef uint16_t uInt16;
typedef uint32_t uInt32;
typedef uint64_t uInt64;
2015-05-23 13:35:12 +02:00
typedef signed int sInt;
typedef signed long sLong;
typedef int8_t sInt8;
typedef int16_t sInt16;
typedef int32_t sInt32;
typedef int64_t sInt64;
2015-05-23 13:35:12 +02:00
typedef long double lDouble;
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FObject
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FObject
{
public:
struct timer_data
{
int id;
timeval interval;
timeval timeout;
FObject* object;
};
// Typedef
typedef std::list<FObject*> FObjectList;
2015-05-23 13:35:12 +02:00
// Constructor
2015-09-27 16:45:28 +02:00
explicit FObject (FObject* = 0);
// Destructor
2015-05-23 13:35:12 +02:00
virtual ~FObject();
// Accessors
2015-05-23 13:35:12 +02:00
virtual const char* getClassName() const;
FObject* getParent() const;
FObjectList getChildren() const;
int numOfChildren() const;
// Inquiries
bool hasParent() const;
bool hasChildren() const;
bool isTimerInUpdating() const;
// Methods
void removeParent();
void addChild (FObject*);
void delChild (FObject*);
2015-05-23 13:35:12 +02:00
// Timer methods
static void getCurrentTime (timeval&);
int addTimer (int);
bool delTimer (int);
bool delOwnTimer();
bool delAllTimer();
2015-05-23 13:35:12 +02:00
protected:
// Typedef
typedef std::vector<timer_data> TimerList;
// Event handler
virtual bool event (FEvent*);
2015-05-23 13:35:12 +02:00
virtual void onTimer (FTimerEvent*);
// Data Members
static TimerList* timer_list;
2015-05-23 13:35:12 +02:00
private:
// Disable copy constructor
2015-05-23 13:35:12 +02:00
FObject (const FObject&);
// Disable assignment operator (=)
2015-05-23 13:35:12 +02:00
FObject& operator = (const FObject&);
// Data Members
FObject* parent_obj;
FObjectList children_list;
bool has_parent;
static bool timer_modify_lock;
2015-05-23 13:35:12 +02:00
};
#pragma pack(pop)
//----------------------------------------------------------------------
inline const char* FObject::getClassName() const
{ return "FObject"; }
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
inline FObject* FObject::getParent() const
{ return parent_obj; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline FObject::FObjectList FObject::getChildren() const
{ return children_list; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline int FObject::numOfChildren() const
{ return int(children_list.size()); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FObject::hasParent() const
{ return has_parent; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FObject::hasChildren() const
{ return bool( ! children_list.empty() ); }
//----------------------------------------------------------------------
inline bool FObject::isTimerInUpdating() const
{ return timer_modify_lock; }
//----------------------------------------------------------------------
inline void FObject::removeParent()
{ parent_obj = 0; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// Operator functions for timeval
//----------------------------------------------------------------------
static inline timeval operator + (const timeval& t1, const timeval& t2)
{
timeval tmp;
tmp.tv_sec = t1.tv_sec + t2.tv_sec;
2015-05-23 13:35:12 +02:00
if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 )
{
tmp.tv_sec++;
tmp.tv_usec -= 1000000;
}
2015-05-23 13:35:12 +02:00
return tmp;
}
//----------------------------------------------------------------------
static inline timeval operator - (const timeval& t1, const timeval& t2)
{
timeval tmp;
tmp.tv_sec = t1.tv_sec - t2.tv_sec;
2015-05-23 13:35:12 +02:00
if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 )
{
tmp.tv_sec--;
tmp.tv_usec += 1000000;
}
2015-05-23 13:35:12 +02:00
return tmp;
}
//----------------------------------------------------------------------
static inline timeval& operator += (timeval& t1, const timeval& t2)
{
t1.tv_sec += t2.tv_sec;
2015-05-23 13:35:12 +02:00
if ( (t1.tv_usec += t2.tv_usec) >= 1000000 )
{
t1.tv_sec++;
t1.tv_usec -= 1000000;
}
2015-05-23 13:35:12 +02:00
return t1;
}
//----------------------------------------------------------------------
static inline bool operator < (const timeval& t1, const timeval& t2)
{
return (t1.tv_sec < t2.tv_sec)
|| (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec);
}
#endif // _FOBJECT_H