00001
00002
00003 #include <OnXSvc/MetaType.h>
00004
00005
00006 #include <Lib/Property.h>
00007 #include <Lib/Variable.h>
00008
00009
00010 #include <GaudiIntrospection/IIntrospectionSvc.h>
00011 #include <GaudiIntrospection/MetaClass.h>
00012 #include <GaudiIntrospection/MetaField.h>
00013
00015 MetaType::MetaType(
00016 IPrinter& aPrinter
00017 ,IIntrospectionSvc* aIntrospectionSvc
00018 )
00019 :BaseType(aPrinter)
00020 ,fIntrospectionSvc(aIntrospectionSvc)
00021 ,fIterator(0)
00024 {
00025 }
00027 bool MetaType::setName(
00028 const std::string& aName
00029 )
00032 {
00033 fType = "";
00034 if(!fIntrospectionSvc) return false;
00035 if(!fIntrospectionSvc->existsClass(aName)) return false;
00036 fType = aName;
00037 return true;
00038 }
00040 const std::string& MetaType::name(
00041 ) const
00044 {
00045 return fType;
00046 }
00048 void MetaType::setIterator(
00049 Lib::IIterator* aIterator
00050 )
00051
00052
00053 {
00054 fIterator = aIterator;
00055 }
00057 Lib::IIterator* MetaType::iterator(
00058 )
00059
00060
00061 {
00062 return fIterator;
00063 }
00065 Lib::Property* MetaType::getProperties(
00066 int& aNumber
00067 )
00068
00069
00070 {
00071 aNumber = 0;
00072
00073
00074
00075 MetaClass& metaClass = const_cast<MetaClass&>(fIntrospectionSvc->getClass(fType));
00076 std::vector<MetaField*> fields = metaClass.fields();
00077
00078 unsigned int number = fields.size();
00079
00080
00081 if(number<=0) return 0;
00082 Lib::Property* list = new Lib::Property[number];
00083 if(!list) return 0;
00084
00085 for( unsigned int i = 0; i < number; i++ ) {
00086 list[i].set(fields[i]->name(),Lib::Property::DOUBLE);
00087
00088 }
00089
00090 aNumber = number;
00091 return list;
00092 }
00094 Lib::Variable MetaType::value(
00095 Lib::Identifier aIdentifier
00096 ,const std::string& aName
00097 )
00098
00099
00100 {
00101 MetaClass& metaClass = const_cast<MetaClass&>(fIntrospectionSvc->getClass(fType));
00102 std::vector<MetaField*> fields = metaClass.fields();
00103 for( unsigned int i = 0; i < fields.size(); i++ ) {
00104 if(aName==fields[i]->name()) {
00105 double value = 0;
00106 return Lib::Variable(printer(),fields[i]->get(aIdentifier,value));
00107 }
00108 }
00109 return Lib::Variable(printer());
00110 }