• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • objects
object_calcer.h
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #ifndef KIG_OBJECTS_OBJECT_CALCER_H
19 #define KIG_OBJECTS_OBJECT_CALCER_H
20 
21 #include <typeinfo>
22 #include "common.h"
23 #include "../misc/boost_intrusive_pointer.hpp"
24 
25 class ObjectCalcer;
26 
27 void intrusive_ptr_add_ref( ObjectCalcer* p );
28 void intrusive_ptr_release( ObjectCalcer* p );
29 
66 class ObjectCalcer
67 {
68 protected:
75  friend void intrusive_ptr_add_ref( ObjectCalcer* p );
76  friend void intrusive_ptr_release( ObjectCalcer* p );
77  int refcount;
78  void ref();
79  void deref();
80 
81  // we keep track of our children, so algorithms can easily walk over
82  // the dependency graph..
83 
84  std::vector<ObjectCalcer*> mchildren;
85 
86  ObjectCalcer();
87 public:
92  void addChild( ObjectCalcer* c );
98  void delChild( ObjectCalcer* c );
99 
100  // use this pointer type to keep a reference to an ObjectCalcer...
101  typedef myboost::intrusive_ptr<ObjectCalcer> shared_ptr;
102 
106  std::vector<ObjectCalcer*> children() const;
107 
108  virtual ~ObjectCalcer();
112  virtual std::vector<ObjectCalcer*> parents() const = 0;
116  virtual const ObjectImp* imp() const = 0;
121  virtual void calc( const KigDocument& ) = 0;
122 
133  virtual const ObjectImpType* impRequirement(
134  ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const = 0;
135 
139  virtual bool canMove() const;
145  virtual bool isFreelyTranslatable() const;
152  virtual std::vector<ObjectCalcer*> movableParents() const;
159  virtual Coordinate moveReferencePoint() const;
167  virtual void move( const Coordinate& to, const KigDocument& doc );
168 
175  virtual bool isDefinedOnOrThrough( const ObjectCalcer* o ) const = 0;
176 };
177 
183 class ObjectTypeCalcer
184  : public ObjectCalcer
185 {
186  std::vector<ObjectCalcer*> mparents;
187  const ObjectType* mtype;
188  ObjectImp* mimp;
189 public:
190  typedef myboost::intrusive_ptr<ObjectTypeCalcer> shared_ptr;
194 // ObjectTypeCalcer( const ObjectType* type, const std::vector<ObjectCalcer*>& parents );
199  ObjectTypeCalcer( const ObjectType* type, const std::vector<ObjectCalcer*>& parents, bool sort=true );
200  ~ObjectTypeCalcer();
201 
202  const ObjectImp* imp() const;
203  std::vector<ObjectCalcer*> parents() const;
204  void calc( const KigDocument& doc );
205 
211  void setParents( const std::vector<ObjectCalcer*> np );
212  void setType( const ObjectType* t );
213 
214  const ObjectType* type() const;
215 
216  const ObjectImpType* impRequirement(
217  ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const;
218  bool isDefinedOnOrThrough( const ObjectCalcer* o ) const;
219  bool canMove() const;
220  bool isFreelyTranslatable() const;
221  std::vector<ObjectCalcer*> movableParents() const;
222  Coordinate moveReferencePoint() const;
223  void move( const Coordinate& to, const KigDocument& doc );
224 };
225 
232 class ObjectConstCalcer
233  : public ObjectCalcer
234 {
235  ObjectImp* mimp;
236 public:
237  typedef myboost::intrusive_ptr<ObjectConstCalcer> shared_ptr;
238 
247  ObjectConstCalcer( ObjectImp* imp );
248  ~ObjectConstCalcer();
249 
250  const ObjectImp* imp() const;
251  void calc( const KigDocument& doc );
252  std::vector<ObjectCalcer*> parents() const;
253 
258  void setImp( ObjectImp* newimp );
263  ObjectImp* switchImp( ObjectImp* newimp );
264 
265  const ObjectImpType* impRequirement(
266  ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const;
267  bool isDefinedOnOrThrough( const ObjectCalcer* o ) const;
268 };
269 
276 class ObjectPropertyCalcer
277  : public ObjectCalcer
278 {
279  ObjectImp* mimp;
280  ObjectCalcer* mparent;
281  int mpropgid;
282 /*
283  * The following two variables are used for a caching
284  * mechanism to avoid computing the Lid corresponding to
285  * a Gid each time. The "typeid" function in C++ is
286  * used to compare the object class of the parent Imp;
287  * the new Lid is computed only when the object class
288  * of the parent imp changes.
289  * As an alternative we could use "type" that each
290  * object imp provides, but this is not completely
291  * safe since in future extensions, in principle, two
292  * different ObjectImps could return the same "type"
293  * (although this is quite unlikely to happen)
294  */
295  mutable int mpropid;
296 // mutable const ObjectImpType* mparenttype;
297  mutable const std::type_info* mparenttype;
298 public:
303  ObjectPropertyCalcer( ObjectCalcer* parent, int propid, bool islocal );
304  ObjectPropertyCalcer( ObjectCalcer* parent, const char* pintname );
305  ~ObjectPropertyCalcer();
306 
307  const ObjectImp* imp() const;
308  std::vector<ObjectCalcer*> parents() const;
309  void calc( const KigDocument& doc );
310 
311  ObjectCalcer* parent() const;
312 
313  const ObjectImpType* impRequirement(
314  ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const;
315  bool isDefinedOnOrThrough( const ObjectCalcer* o ) const;
316 
317  int propLid() const;
318  int propGid() const;
319 };
320 
321 #endif
ObjectCalcer::isFreelyTranslatable
virtual bool isFreelyTranslatable() const
Returns whether this ObjectCalcer can be translated at any position in the coordinate plane...
Definition: object_calcer.cc:265
ObjectConstCalcer::switchImp
ObjectImp * switchImp(ObjectImp *newimp)
Set the ObjectImp of this ObjectConstCalcer to the given newimp.
Definition: object_calcer.cc:202
ObjectTypeCalcer::move
void move(const Coordinate &to, const KigDocument &doc)
This is the method that does the real moving work.
Definition: object_calcer.cc:296
ObjectImpType
Instances of this class represent a certain ObjectImp type.
Definition: object_imp.h:95
ObjectConstCalcer::imp
const ObjectImp * imp() const
Returns the ObjectImp of this ObjectCalcer.
Definition: object_calcer.cc:65
ObjectConstCalcer::setImp
void setImp(ObjectImp *newimp)
Set the ObjectImp of this ObjectConstCalcer to the given newimp.
Definition: object_calcer.cc:241
ObjectCalcer::moveReferencePoint
virtual Coordinate moveReferencePoint() const
In order to support simultaneously moving objects that are in different locations, we need for each object a location that it is assumed to be at, at the moment the moving starts.
Definition: object_calcer.cc:270
ObjectCalcer::move
virtual void move(const Coordinate &to, const KigDocument &doc)
This is the method that does the real moving work.
Definition: object_calcer.cc:276
ObjectTypeCalcer::setParents
void setParents(const std::vector< ObjectCalcer * > np)
Set the parents of this ObjectTypeCalcer to np.
Definition: object_calcer.cc:246
ObjectConstCalcer
This is an ObjectCalcer that keeps an ObjectImp, and never calculates a new one.
Definition: object_calcer.h:232
ObjectConstCalcer::shared_ptr
myboost::intrusive_ptr< ObjectConstCalcer > shared_ptr
Definition: object_calcer.h:237
ObjectTypeCalcer::setType
void setType(const ObjectType *t)
Definition: object_calcer.cc:255
ObjectPropertyCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:176
ObjectCalcer::movableParents
virtual std::vector< ObjectCalcer * > movableParents() const
Moving an object most of the time signifies invoking changes in some of its parents.
Definition: object_calcer.cc:316
ObjectTypeCalcer::moveReferencePoint
Coordinate moveReferencePoint() const
In order to support simultaneously moving objects that are in different locations, we need for each object a location that it is assumed to be at, at the moment the moving starts.
Definition: object_calcer.cc:291
ObjectCalcer::intrusive_ptr_release
friend void intrusive_ptr_release(ObjectCalcer *p)
Definition: object_calcer.cc:95
ObjectConstCalcer::calc
void calc(const KigDocument &doc)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
Definition: object_calcer.cc:70
ObjectPropertyCalcer::ObjectPropertyCalcer
ObjectPropertyCalcer(ObjectCalcer *parent, int propid, bool islocal)
Construct a new ObjectPropertyCalcer, that will get the property from parent with number propid...
Definition: object_calcer.cc:147
ObjectTypeCalcer
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
Definition: object_calcer.h:183
ObjectPropertyCalcer::isDefinedOnOrThrough
bool isDefinedOnOrThrough(const ObjectCalcer *o) const
If this ObjectCalcer represents a curve, return true if the given point is by construction on this cu...
Definition: object_calcer.cc:331
myboost::intrusive_ptr< ObjectCalcer >
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
ObjectCalcer::shared_ptr
myboost::intrusive_ptr< ObjectCalcer > shared_ptr
Definition: object_calcer.h:101
ObjectCalcer::intrusive_ptr_add_ref
friend void intrusive_ptr_add_ref(ObjectCalcer *p)
ObjectCalcer's are reference counted.
Definition: object_calcer.cc:90
ObjectPropertyCalcer::calc
void calc(const KigDocument &doc)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
Definition: object_calcer.cc:183
ObjectTypeCalcer::movableParents
std::vector< ObjectCalcer * > movableParents() const
Moving an object most of the time signifies invoking changes in some of its parents.
Definition: object_calcer.cc:321
common.h
ObjectCalcer::~ObjectCalcer
virtual ~ObjectCalcer()
Definition: object_calcer.cc:51
ObjectTypeCalcer::canMove
bool canMove() const
Returns whether this ObjectCalcer supports moving.
Definition: object_calcer.cc:281
ObjectTypeCalcer::impRequirement
const ObjectImpType * impRequirement(ObjectCalcer *o, const std::vector< ObjectCalcer * > &os) const
An ObjectCalcer expects its parents to have an ObjectImp of a certain type.
Definition: object_calcer.cc:228
ObjectTypeCalcer::imp
const ObjectImp * imp() const
Returns the ObjectImp of this ObjectCalcer.
Definition: object_calcer.cc:100
ObjectCalcer
An ObjectCalcer is an object that represents an algorithm for calculating an ObjectImp from other Obj...
Definition: object_calcer.h:66
ObjectPropertyCalcer::propLid
int propLid() const
Definition: object_calcer.cc:352
ObjectConstCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:74
ObjectTypeCalcer::ObjectTypeCalcer
ObjectTypeCalcer(const ObjectType *type, const std::vector< ObjectCalcer * > &parents, bool sort=true)
Construct a new ObjectTypeCalcer with a given type and parents.
Definition: object_calcer.cc:43
ObjectCalcer::calc
virtual void calc(const KigDocument &)=0
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
ObjectCalcer::refcount
int refcount
Definition: object_calcer.h:77
ObjectPropertyCalcer
This is an ObjectCalcer that has a single parent, and gets a certain property from it in its calc() m...
Definition: object_calcer.h:276
ObjectType
The ObjectType class is a thing that represents the "behaviour" for a certain type.
Definition: object_type.h:32
ObjectTypeCalcer::type
const ObjectType * type() const
Definition: object_calcer.cc:132
ObjectConstCalcer::ObjectConstCalcer
ObjectConstCalcer(ObjectImp *imp)
Construct a new ObjectConstCalcer with the given imp as the stored ObjectImp.
Definition: object_calcer.cc:55
ObjectCalcer::ref
void ref()
Definition: object_calcer.cc:80
ObjectPropertyCalcer::imp
const ObjectImp * imp() const
Returns the ObjectImp of this ObjectCalcer.
Definition: object_calcer.cc:171
ObjectCalcer::canMove
virtual bool canMove() const
Returns whether this ObjectCalcer supports moving.
Definition: object_calcer.cc:260
ObjectPropertyCalcer::propGid
int propGid() const
Definition: object_calcer.cc:357
ObjectCalcer::mchildren
std::vector< ObjectCalcer * > mchildren
Definition: object_calcer.h:84
ObjectTypeCalcer::isDefinedOnOrThrough
bool isDefinedOnOrThrough(const ObjectCalcer *o) const
If this ObjectCalcer represents a curve, return true if the given point is by construction on this cu...
Definition: object_calcer.cc:338
ObjectCalcer::impRequirement
virtual const ObjectImpType * impRequirement(ObjectCalcer *o, const std::vector< ObjectCalcer * > &os) const =0
An ObjectCalcer expects its parents to have an ObjectImp of a certain type.
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
ObjectTypeCalcer::shared_ptr
myboost::intrusive_ptr< ObjectTypeCalcer > shared_ptr
Definition: object_calcer.h:190
ObjectTypeCalcer::isFreelyTranslatable
bool isFreelyTranslatable() const
Returns whether this ObjectCalcer can be translated at any position in the coordinate plane...
Definition: object_calcer.cc:286
ObjectCalcer::imp
virtual const ObjectImp * imp() const =0
Returns the ObjectImp of this ObjectCalcer.
ObjectTypeCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:105
ObjectTypeCalcer::~ObjectTypeCalcer
~ObjectTypeCalcer()
Definition: object_calcer.cc:125
intrusive_ptr_release
void intrusive_ptr_release(ObjectCalcer *p)
Definition: object_calcer.cc:95
ObjectCalcer::children
std::vector< ObjectCalcer * > children() const
Returns the child ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:209
ObjectConstCalcer::isDefinedOnOrThrough
bool isDefinedOnOrThrough(const ObjectCalcer *o) const
If this ObjectCalcer represents a curve, return true if the given point is by construction on this cu...
Definition: object_calcer.cc:326
ObjectTypeCalcer::calc
void calc(const KigDocument &doc)
Makes the ObjectCalcer recalculate its ObjectImp from its parents.
Definition: object_calcer.cc:32
ObjectConstCalcer::~ObjectConstCalcer
~ObjectConstCalcer()
Definition: object_calcer.cc:60
ObjectCalcer::addChild
void addChild(ObjectCalcer *c)
a calcer should call this to register itself as a child of this calcer.
Definition: object_calcer.cc:110
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
ObjectCalcer::parents
virtual std::vector< ObjectCalcer * > parents() const =0
Returns the parent ObjectCalcer's of this ObjectCalcer.
ObjectCalcer::delChild
void delChild(ObjectCalcer *c)
a calcer should call this in its destructor, to inform its parent that it is no longer a child of thi...
Definition: object_calcer.cc:116
ObjectConstCalcer::impRequirement
const ObjectImpType * impRequirement(ObjectCalcer *o, const std::vector< ObjectCalcer * > &os) const
An ObjectCalcer expects its parents to have an ObjectImp of a certain type.
Definition: object_calcer.cc:221
ObjectCalcer::ObjectCalcer
ObjectCalcer()
Definition: object_calcer.cc:311
ObjectCalcer::deref
void deref()
Definition: object_calcer.cc:85
ObjectPropertyCalcer::parent
ObjectCalcer * parent() const
Definition: object_calcer.cc:306
intrusive_ptr_add_ref
void intrusive_ptr_add_ref(ObjectCalcer *p)
Definition: object_calcer.cc:90
ObjectPropertyCalcer::impRequirement
const ObjectImpType * impRequirement(ObjectCalcer *o, const std::vector< ObjectCalcer * > &os) const
An ObjectCalcer expects its parents to have an ObjectImp of a certain type.
Definition: object_calcer.cc:214
ObjectPropertyCalcer::~ObjectPropertyCalcer
~ObjectPropertyCalcer()
Definition: object_calcer.cc:162
ObjectCalcer::isDefinedOnOrThrough
virtual bool isDefinedOnOrThrough(const ObjectCalcer *o) const =0
If this ObjectCalcer represents a curve, return true if the given point is by construction on this cu...
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal