2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fobject.h - Object container base class of all widget objects *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
|
|
|
* Copyright 2015-2017 Markus Gans *
|
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Base class
|
|
|
|
* ══════════
|
|
|
|
*
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FObject ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FOBJECT_H
|
|
|
|
#define FOBJECT_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2017-02-25 15:18:29 +01:00
|
|
|
#include <stdint.h>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <sys/time.h> // need for gettimeofday
|
2015-05-23 13:35:12 +02:00
|
|
|
#include <cstdlib>
|
2017-07-23 01:19:59 +02:00
|
|
|
#include <cstring>
|
2015-05-23 13:35:12 +02:00
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
2015-08-22 18:53:52 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fc.h"
|
|
|
|
#include "final/fevent.h"
|
|
|
|
#include "final/ftypes.h"
|
2015-09-25 21:37:19 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FObject
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FObject
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Typedef
|
|
|
|
typedef std::list<FObject*> FObjectList;
|
2017-09-15 01:31:02 +02:00
|
|
|
typedef FObjectList::iterator FObjectIterator;
|
|
|
|
typedef FObjectList::const_iterator constFObjectIterator;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
explicit FObject (FObject* = 0);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
virtual ~FObject();
|
|
|
|
|
|
|
|
// Accessors
|
2017-09-17 01:50:41 +02:00
|
|
|
virtual const char* getClassName() const;
|
|
|
|
FObject* getParent() const;
|
|
|
|
FObject* getChild (int) const;
|
|
|
|
const FObjectList& getChildren() const;
|
|
|
|
int numOfChildren() const;
|
|
|
|
FObjectIterator begin();
|
|
|
|
FObjectIterator end();
|
|
|
|
constFObjectIterator begin() const;
|
|
|
|
constFObjectIterator end() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiries
|
2017-09-17 01:50:41 +02:00
|
|
|
bool hasParent() const;
|
|
|
|
bool hasChildren() const;
|
|
|
|
bool isChild (FObject*) const;
|
|
|
|
bool isDirectChild (FObject*) const;
|
|
|
|
bool isWidget() const;
|
|
|
|
bool isInstanceOf (const char*) const;
|
|
|
|
bool isTimerInUpdating() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2017-09-17 01:50:41 +02:00
|
|
|
void removeParent();
|
|
|
|
void addChild (FObject*);
|
|
|
|
void delChild (FObject*);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Timer methods
|
2017-09-17 01:50:41 +02:00
|
|
|
static void getCurrentTime (timeval*);
|
|
|
|
int addTimer (int);
|
|
|
|
bool delTimer (int);
|
|
|
|
bool delOwnTimer();
|
|
|
|
bool delAllTimer();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
struct timer_data
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
timeval interval;
|
|
|
|
timeval timeout;
|
|
|
|
FObject* object;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Typedef
|
|
|
|
typedef std::vector<timer_data> TimerList;
|
|
|
|
|
|
|
|
// Event handler
|
|
|
|
virtual bool event (FEvent*);
|
|
|
|
virtual void onTimer (FTimerEvent*);
|
|
|
|
|
|
|
|
// Data Members
|
|
|
|
static TimerList* timer_list;
|
|
|
|
bool widget_object;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
|
|
|
FObject (const FObject&);
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
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
|
2016-09-27 00:46:05 +02:00
|
|
|
{ return parent_obj; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-08-24 00:47:35 +02:00
|
|
|
inline const FObject::FObjectList& FObject::getChildren() const
|
2016-11-02 00:37:58 +01:00
|
|
|
{ return children_list; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline int FObject::numOfChildren() const
|
|
|
|
{ return int(children_list.size()); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator FObject::begin()
|
|
|
|
{ return children_list.begin(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::FObjectIterator FObject::end()
|
|
|
|
{ return children_list.end(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::constFObjectIterator FObject::begin() const
|
|
|
|
{ return children_list.begin(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FObject::constFObjectIterator FObject::end() const
|
|
|
|
{ return children_list.end(); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01: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() ); }
|
|
|
|
|
2017-03-08 23:48:30 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FObject::isDirectChild (FObject* obj) const
|
|
|
|
{ return bool( obj->getParent() == this ); }
|
|
|
|
|
2017-06-11 17:47:50 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FObject::isWidget() const
|
|
|
|
{ return widget_object; }
|
|
|
|
|
2017-07-23 01:19:59 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FObject::isInstanceOf (const char* classname) const
|
|
|
|
{ return ( classname ) ? bool(strcmp(classname, getClassName()) == 0) : false; }
|
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FObject::isTimerInUpdating() const
|
|
|
|
{ return timer_modify_lock; }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FObject::removeParent()
|
2017-10-14 20:21:44 +02:00
|
|
|
{
|
|
|
|
parent_obj = 0;
|
|
|
|
has_parent = false;
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
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;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( (t1.tv_usec += t2.tv_usec) >= 1000000 )
|
|
|
|
{
|
|
|
|
t1.tv_sec++;
|
|
|
|
t1.tv_usec -= 1000000;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FOBJECT_H
|