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

step/stepcore

  • sources
  • kde-4.12
  • kdeedu
  • step
  • stepcore
object.cc
Go to the documentation of this file.
1 /* This file is part of StepCore library.
2  Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
3 
4  StepCore library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  StepCore library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with StepCore; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "object.h"
20 #include <cstring>
21 #include <QtGlobal>
22 #include <QCoreApplication>
23 
24 namespace StepCore {
25 
26 STEPCORE_META_OBJECT(Object, QT_TRANSLATE_NOOP("ObjectClass", "Object"), QT_TR_NOOP("Object"), MetaObject::ABSTRACT,,
27  STEPCORE_PROPERTY_RW(QString, name, QT_TRANSLATE_NOOP("PropertyName", "name"), STEPCORE_UNITS_NULL, QT_TR_NOOP("Object name"), name, setName))
28 
29 int MetaObject::s_classIdCount = 0;
30 
31 void MetaObject::copyProperties(const MetaProperty** dest) const
32 {
33  int c = 0;
34  for(int i=0; i<superClassCount(); ++i) {
35  superClass(i)->copyProperties(dest + c);
36  c += superClass(i)->propertyCount();
37  }
38  for(int i=0; i<_classPropertyCount; ++i) {
39  dest[c+i] = _classProperties + i;
40  }
41 }
42 
43 void MetaObject::init() const
44 {
45  if(_initialized) return;
46 
47  // properties
48  _allPropertyCount = classPropertyCount();
49  for(int i=0; i<superClassCount(); ++i) {
50  _allPropertyCount += superClass(i)->propertyCount();
51  }
52 
53  _allProperties = new const MetaProperty*[_allPropertyCount];
54  copyProperties(_allProperties);
55 
56  // classId and super classes
57  _classId = s_classIdCount++; // all super classes is already registered
58  _allSuperClassIds.fill(false, s_classIdCount);
59  _allSuperClassIds.setBit(_classId);
60  for(int i=0; i<superClassCount(); ++i) {
61  _allSuperClassIds |= superClass(i)->_allSuperClassIds;
62  }
63 
64  // strings
65  _classNameTr = QCoreApplication::translate("ObjectClass", _className.toUtf8().constData(),
66  NULL, QCoreApplication::UnicodeUTF8);
67  _descriptionTr = QCoreApplication::translate(NULL, _description.toUtf8().constData(),
68  NULL, QCoreApplication::UnicodeUTF8);
69 
70  _initialized = true;
71 }
72 
73 bool MetaObject::inherits(const MetaObject* obj) const
74 {
75  if(!_initialized) init();
76  int objClassId = obj->classId();
77  if(objClassId == _classId) return true;
78  else if(objClassId > _classId) return false;
79  return _allSuperClassIds.testBit(objClassId);
80 }
81 
82 bool MetaObject::inherits(const char* name) const
83 {
84  //if(std::strcmp(className(), name) == 0) return true;
85  if(className() == name) return true;
86  for(int i=superClassCount()-1; i>=0; --i) {
87  if(superClass(i)->inherits(name)) return true;
88  }
89  return false;
90 }
91 
92 /*
93 int MetaObject::propertyCount() const
94 {
95  if(_allPropertyCount >= 0) return _allPropertyCount;
96 
97  _allPropertyCount = 0;
98  for(int i=0; i<superClassCount(); ++i)
99  _allPropertyCount += superClass(i)->propertyCount();
100  _allPropertyCount += classPropertyCount();
101  return _allPropertyCount;
102 }*/
103 
104 /*
105 const MetaProperty* MetaObject::property(int n) const
106 {
107  for(int i=0; i<superClassCount(); ++i) {
108  const MetaProperty* pr = superClass(i)->property(n);
109  if(pr) return pr;
110  n -= superClass(i)->propertyCount();
111  }
112  if(n < classPropertyCount()) return &_classProperties[n];
113  else return NULL;
114 }*/
115 
116 void MetaProperty::init() const
117 {
118  _nameTr = QCoreApplication::translate("PropertyName", _name.toUtf8().constData(),
119  NULL, QCoreApplication::UnicodeUTF8);
120  _unitsTr = QCoreApplication::translate("Units", _units.toUtf8().constData(),
121  NULL, QCoreApplication::UnicodeUTF8);
122  _descriptionTr = QCoreApplication::translate(NULL, _description.toUtf8().constData(),
123  NULL, QCoreApplication::UnicodeUTF8);
124  _initialized = true;
125 }
126 
127 const MetaProperty* MetaObject::property(const QString& name) const
128 {
129  if(!_initialized) init();
130  for(int i=0; i<_allPropertyCount; ++i) {
131  //if(std::strcmp(_allProperties[i]->name(), name) == 0)
132  if(_allProperties[i]->name() == name)
133  return _allProperties[i];
134  }
135  /*
136  for(int i=0; i<classPropertyCount(); ++i) {
137  if(std::strcmp(classProperty(i)->name(), name) == 0)
138  return classProperty(i);
139  }*/
140  /*
141  for(int i=superClassCount()-1; i>=0; --i) {
142  const MetaProperty* pr = superClass(i)->property(name);
143  if(pr) return pr;
144  }*/
145  return NULL;
146 }
147 
148 } // namespace StepCore
149 
StepCore::MetaObject::className
const QString & className() const
Returns class name.
Definition: object.h:185
StepCore::MetaObject::superClassCount
int superClassCount() const
Returns number of direct bases.
Definition: object.h:205
StepCore::MetaProperty::_unitsTr
QString _unitsTr
Definition: object.h:165
StepCore::MetaProperty::_initialized
bool _initialized
Definition: object.h:163
StepCore::MetaObject::_classNameTr
QString _classNameTr
Definition: object.h:254
StepCore::MetaObject::propertyCount
int propertyCount() const
Returns property count.
Definition: object.h:225
StepCore::MetaProperty::_nameTr
QString _nameTr
Definition: object.h:164
StepCore::MetaObject::_allPropertyCount
int _allPropertyCount
Definition: object.h:249
StepCore::MetaObject::_allSuperClassIds
QBitArray _allSuperClassIds
Definition: object.h:252
StepCore::MetaObject::inherits
bool inherits() const
Returns true if this class inherits class T.
Definition: object.h:211
StepCore::MetaObject::_initialized
bool _initialized
Definition: object.h:247
StepCore::MetaProperty::_units
const QString _units
Definition: object.h:154
StepCore::QT_TRANSLATE_NOOP
QT_TRANSLATE_NOOP("ObjectClass","GJKCollisionSolver")
StepCore::MetaObject::property
const MetaProperty * property(int n) const
Returns property by index.
Definition: object.h:227
StepCore::MetaObject::_classId
int _classId
Definition: object.h:251
StepCore::MetaObject::_description
const QString _description
Definition: object.h:237
StepCore::MetaObject::ABSTRACT
Class is abstract.
Definition: object.h:180
StepCore::QT_TR_NOOP
QT_TR_NOOP("Errors class for CoulombForce")
StepCore::STEPCORE_PROPERTY_RW
STEPCORE_PROPERTY_RW(double, depth, QT_TRANSLATE_NOOP("PropertyName","depth"), QT_TRANSLATE_NOOP("Units","J"), QT_TR_NOOP("Potential depth"), depth, setDepth) STEPCORE_PROPERTY_RW(double
StepCore::MetaProperty::_description
const QString _description
Definition: object.h:155
STEPCORE_UNITS_NULL
#define STEPCORE_UNITS_NULL
Definition: object.h:365
StepCore::MetaObject::_allProperties
const MetaProperty ** _allProperties
Definition: object.h:248
StepCore::MetaProperty::_descriptionTr
QString _descriptionTr
Definition: object.h:166
object.h
Object, MetaObject and MetaProperty classes.
StepCore::MetaObject::_descriptionTr
QString _descriptionTr
Definition: object.h:255
StepCore::MetaObject::superClass
const MetaObject * superClass(int n) const
Returns direct base.
Definition: object.h:207
StepCore::MetaObject::classPropertyCount
int classPropertyCount() const
Returns number of non-inherited properties.
Definition: object.h:220
StepCore::MetaObject::init
void init() const
Definition: object.cc:43
StepCore::MetaProperty::init
void init() const
Definition: object.cc:116
StepCore::MetaObject
Meta-information about class.
Definition: object.h:176
StepCore::STEPCORE_META_OBJECT
STEPCORE_META_OBJECT(CollisionSolver, QT_TRANSLATE_NOOP("ObjectClass","CollisionSolver"),"CollisionSolver", MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object), STEPCORE_PROPERTY_RW(double, toleranceAbs, QT_TRANSLATE_NOOP("PropertyName","toleranceAbs"), STEPCORE_UNITS_1, QT_TR_NOOP("Allowed absolute tolerance"), toleranceAbs, setToleranceAbs) STEPCORE_PROPERTY_R_D(double, localError, QT_TRANSLATE_NOOP("PropertyName","localError"), STEPCORE_UNITS_1, QT_TR_NOOP("Maximal local error during last step"), localError)) STEPCORE_META_OBJECT(GJKCollisionSolver
StepCore::MetaProperty
Meta-information about property.
Definition: object.h:77
StepCore::MetaObject::copyProperties
void copyProperties(const MetaProperty **dest) const
StepCore::MetaObject::classId
int classId() const
Returns class id.
Definition: object.h:195
StepCore::MetaProperty::_name
const QString _name
Definition: object.h:153
StepCore::MetaObject::_className
const QString _className
Definition: object.h:236
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:43:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

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