step/stepcore
object.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "object.h"
00020 #include <cstring>
00021
00022 namespace StepCore {
00023
00024 STEPCORE_META_OBJECT(Object, "Object", MetaObject::ABSTRACT,,
00025 STEPCORE_PROPERTY_RW(QString, name, STEPCORE_UNITS_NULL, "Object name", name, setName))
00026
00027 int MetaObject::s_classIdCount = 0;
00028
00029 void MetaObject::copyProperties(const MetaProperty** dest) const
00030 {
00031 int c = 0;
00032 for(int i=0; i<superClassCount(); ++i) {
00033 superClass(i)->copyProperties(dest + c);
00034 c += superClass(i)->propertyCount();
00035 }
00036 for(int i=0; i<_classPropertyCount; ++i) {
00037 dest[c+i] = _classProperties + i;
00038 }
00039 }
00040
00041 void MetaObject::init() const
00042 {
00043 if(_initialized) return;
00044
00045
00046 _allPropertyCount = classPropertyCount();
00047 for(int i=0; i<superClassCount(); ++i) {
00048 _allPropertyCount += superClass(i)->propertyCount();
00049 }
00050
00051 _allProperties = new const MetaProperty*[_allPropertyCount];
00052 copyProperties(_allProperties);
00053
00054
00055 _classId = s_classIdCount++;
00056 _allSuperClassIds.fill(false, s_classIdCount);
00057 _allSuperClassIds.setBit(_classId);
00058 for(int i=0; i<superClassCount(); ++i) {
00059 _allSuperClassIds |= superClass(i)->_allSuperClassIds;
00060 }
00061
00062 _initialized = true;
00063 }
00064
00065 bool MetaObject::inherits(const MetaObject* obj) const
00066 {
00067 if(!_initialized) init();
00068 int objClassId = obj->classId();
00069 if(objClassId == _classId) return true;
00070 else if(objClassId > _classId) return false;
00071 return _allSuperClassIds.testBit(objClassId);
00072 }
00073
00074 bool MetaObject::inherits(const char* name) const
00075 {
00076
00077 if(className() == name) return true;
00078 for(int i=superClassCount()-1; i>=0; --i) {
00079 if(superClass(i)->inherits(name)) return true;
00080 }
00081 return false;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 const MetaProperty* MetaObject::property(const QString& name) const
00109 {
00110 if(!_initialized) init();
00111 for(int i=0; i<_allPropertyCount; ++i) {
00112
00113 if(_allProperties[i]->name() == name)
00114 return _allProperties[i];
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 return NULL;
00127 }
00128
00129 }
00130