1 /***************************************************************************
2 object.cpp: abstract base class for all Kst objects
3 -------------------
4 begin : May 25, 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 #include "object.h"
19
20 class ScriptInterface;
21
22 #include "objectstore.h"
23
24 namespace Kst {
25
26 const QString Object::staticTypeString = "Object";
27
Object()28 Object::Object() :
29 Shared(), KstRWLock(), NamedObject(),
30 _store(0L), _serial(0), _serialOfLastChange(0), _interface(0)
31 {
32 }
33
34
~Object()35 Object::~Object() {
36 }
37
38
type()39 QString Object::type() {
40 return staticMetaObject.className();
41 }
42
reset()43 void Object::reset() {
44 _serial = _serialOfLastChange = Forced;
45 }
46
typeString() const47 const QString& Object::typeString() const {
48 return staticTypeString;
49 }
50
createScriptInterface()51 ScriptInterface* Object::createScriptInterface() {
52 return NULL;
53 }
54
scriptInterface()55 ScriptInterface* Object::scriptInterface() {
56 if (!_interface) {
57 _interface = createScriptInterface();
58 }
59 return _interface;
60 }
61
62
63 // Returns count - 1 to account for "this" and the list pointer, therefore
64 // you MUST have a reference-counted pointer to call this function
getUsage() const65 int Object::getUsage() const {
66 return _KShared_count() - 1;
67 }
68
69
deleteDependents()70 void Object::deleteDependents() {
71 QList<ObjectPtr> Objects = _store->objectList();
72 foreach (ObjectPtr object, Objects) {
73 if (object->uses(this)) {
74 _store->removeObject(object);
75 }
76 }
77 }
78
79
uses(ObjectPtr p) const80 bool Object::uses(ObjectPtr p) const {
81 Q_UNUSED(p)
82
83 return false;
84 }
85
86
store() const87 ObjectStore* Object::store() const {
88 return _store;
89 }
90
91 // decide, based on serial numbers, whether to do an update.
92 // if all inputs are up to date, update. Otherwise, defer.
objectUpdate(qint64 newSerial)93 Object::UpdateType Object::objectUpdate(qint64 newSerial) {
94 Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
95
96 if (newSerial == _serial) {
97 return NoChange;
98 }
99
100 if (newSerial == Forced) { // register the forced update, but don't do it now.
101 //qDebug()<<"Forced, def";
102 _serial = Forced;
103 return Deferred;
104 } else if (minInputSerial() < newSerial) { // if an input was forced, this will be true
105 return Deferred;
106 } else if ((_serialOfLastChange < maxInputSerialOfLastChange()) || (_serial == Object::Forced)) {
107 internalUpdate();
108 _serialOfLastChange = newSerial;
109 _serial = newSerial;
110 return Updated;
111 } else {
112 _serial = newSerial;
113 return NoChange;
114 }
115 }
116 }
117
118 // vim: ts=2 sw=2 et
119