1 /***************************************************************************
2                  object.h: abstract base class for all Kst objects
3                              -------------------
4     begin                : May 22, 2003
5     copyright            : (C) 2003 The University of Toronto
6     email                : netterfield@astro.utoronto.ca
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef OBJECT_H
19 #define OBJECT_H
20 
21 #include <QPointer>
22 #include <QMutex>
23 #include <QObject>
24 #include <QString>
25 #include <QDebug>
26 #include <QStringList>
27 #include <QMetaType>
28 #include <QXmlStreamWriter>
29 
30 #include "namedobject.h"
31 #include "kst_export.h"
32 #include "sharedptr.h"
33 #include "rwlock.h"
34 
35 namespace Kst {
36 
37 class ObjectStore;
38 class Object;
39 class ScriptInterface;
40 
41 typedef SharedPtr<Object> ObjectPtr;
42 
43 
44 class KSTCORE_EXPORT Object : public QObject, public Shared, public KstRWLock, public NamedObject
45 {
46     Q_OBJECT
47 
48   public:
49     static QString type();
50     static const qint64 Forced = -1;
51     static const qint64 NoInputs = -2;
52 
53     enum UpdateType { NoChange = 0, Updated, Deferred };
54 
55     virtual UpdateType objectUpdate(qint64 newSerial);
registerChange()56     virtual void registerChange() {_serial = Forced; emit dirty();}
57 
58     virtual void reset();
59 
serial()60     qint64 serial() const {return _serial;}
serialOfLastChange()61     qint64 serialOfLastChange() const {return _serialOfLastChange;}
62 
63     virtual const QString& typeString() const;
64     static const QString staticTypeString;
65 
66     ObjectStore *store() const;
67 
68     // Returns count - 2 to account for "this" and the list pointer, therefore
69     // you MUST have a reference-counted pointer to call this function
70     virtual int getUsage() const;
71 
72     virtual void deleteDependents();
73 
74     virtual void internalUpdate() = 0;
75 
used()76     virtual bool used() const {return _used;}
setUsed(bool used_in)77     virtual void setUsed(bool used_in) {_used = used_in;}
78 
79     virtual bool uses(ObjectPtr p) const;
80 
81     virtual ScriptInterface* createScriptInterface();
82     ScriptInterface *scriptInterface();
83 
84   protected:
85     Object();
86     virtual ~Object();
87 
88     friend class ObjectStore;
89     ObjectStore *_store;  // set by ObjectStore
90 
91     virtual qint64 minInputSerial() const = 0;
92     virtual qint64 maxInputSerialOfLastChange() const = 0;
93 
94     qint64 _serial;
95     qint64 _serialOfLastChange;
96     bool _used;
97   private:
98     ScriptInterface *_interface;
99 
100   signals:
101     void dirty();
102   };
103 
104 
105 }
106 
107 Q_DECLARE_METATYPE(Kst::Object*)
108 
109 #endif
110 
111 // vim: ts=2 sw=2 et
112