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

step/stepcore

object.cc

Go to the documentation of this file.
00001 /* This file is part of StepCore library.
00002    Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
00003 
00004    StepCore library is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    StepCore library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with StepCore; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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     // properties
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     // classId and super classes
00055     _classId = s_classIdCount++; // all super classes is already registered
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     //if(std::strcmp(className(), name) == 0) return true;
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 int MetaObject::propertyCount() const
00086 {
00087     if(_allPropertyCount >= 0) return _allPropertyCount;
00088 
00089     _allPropertyCount = 0;
00090     for(int i=0; i<superClassCount(); ++i)
00091         _allPropertyCount += superClass(i)->propertyCount();
00092     _allPropertyCount += classPropertyCount();
00093     return _allPropertyCount;
00094 }*/
00095 
00096 /*
00097 const MetaProperty* MetaObject::property(int n) const
00098 {
00099     for(int i=0; i<superClassCount(); ++i) {
00100         const MetaProperty* pr = superClass(i)->property(n);
00101         if(pr) return pr;
00102         n -= superClass(i)->propertyCount();
00103     }
00104     if(n < classPropertyCount()) return &_classProperties[n];
00105     else return NULL;
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         //if(std::strcmp(_allProperties[i]->name(), name) == 0)
00113         if(_allProperties[i]->name() == name)
00114             return _allProperties[i];
00115     }
00116     /*
00117     for(int i=0; i<classPropertyCount(); ++i) {
00118         if(std::strcmp(classProperty(i)->name(), name) == 0)
00119             return classProperty(i);
00120     }*/
00121     /*
00122     for(int i=superClassCount()-1; i>=0; --i) {
00123         const MetaProperty* pr = superClass(i)->property(name);
00124         if(pr) return pr;
00125     }*/
00126     return NULL;
00127 }
00128 
00129 } // namespace StepCore
00130 

step/stepcore

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

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal