finalcut/src/fobject.h

184 lines
4.4 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 <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 unsigned char uInt8;
typedef unsigned short uInt16;
typedef unsigned int uInt32;
typedef u_int64_t uInt64;
typedef signed int sInt;
typedef signed long sLong;
typedef signed char sInt8;
typedef signed short sInt16;
typedef signed int sInt32;
typedef int64_t sInt64;
typedef long double lDouble;
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FObject
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FObject
{
public:
typedef std::list<FObject*> object_list;
struct timer_data
{
int id;
timeval interval;
timeval timeout;
FObject* object;
};
typedef std::vector<timer_data> TimerList;
static TimerList* timer_list;
private:
FObject* parentObj;
object_list children_list;
bool has_parent;
static bool modify_timer;
friend class FApplication;
public:
2015-09-27 16:45:28 +02:00
explicit FObject (FObject* = 0);
2015-05-23 13:35:12 +02:00
virtual ~FObject();
virtual const char* getClassName() const;
2015-09-20 05:44:50 +02:00
FObject* getParent() const;
2015-05-23 13:35:12 +02:00
bool hasParent() const;
void removeParent();
2015-09-20 05:44:50 +02:00
object_list getChildren() const;
2015-05-23 13:35:12 +02:00
bool hasChildren() const;
void addChild (FObject*);
void delChild (FObject*);
int numOfChildren() const;
static void getCurrentTime (timeval&);
2015-11-12 01:33:16 +01:00
int addTimer (int);
bool delTimer (int);
2015-12-19 20:49:01 +01:00
bool delOwnTimer();
2015-05-23 13:35:12 +02:00
bool delAllTimer();
virtual bool event (FEvent*);
protected:
virtual void onTimer (FTimerEvent*);
private:
FObject (const FObject&);
FObject& operator = (const FObject&);
};
#pragma pack(pop)
//----------------------------------------------------------------------
inline const char* FObject::getClassName() const
{ return "FObject"; }
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
inline FObject* FObject::getParent() const
2015-05-23 13:35:12 +02:00
{ return parentObj; }
//----------------------------------------------------------------------
inline bool FObject::hasParent() const
{ return has_parent; }
//----------------------------------------------------------------------
inline void FObject::removeParent()
{ parentObj = 0; }
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
inline FObject::object_list FObject::getChildren() const
2015-05-23 13:35:12 +02:00
{ return children_list; }
//----------------------------------------------------------------------
inline bool FObject::hasChildren() const
{ return bool( ! children_list.empty() ); }
//----------------------------------------------------------------------
inline int FObject::numOfChildren() const
{ return int(children_list.size()); }
//----------------------------------------------------------------------
// 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