00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef G4ATTUTILS_HH
00033 #define G4ATTUTILS_HH
00034
00035 #include "globals.hh"
00036 #include "G4AttDef.hh"
00037 #include "G4AttValue.hh"
00038 #include "G4String.hh"
00039 #include "G4TypeKey.hh"
00040 #include <map>
00041 #include <vector>
00042
00043 namespace G4AttUtils {
00044
00045 namespace {
00046
00047
00048 template <typename T>
00049 class HasName {
00050 public:
00051 HasName(const G4String& name): fName(name) {};
00052 bool operator()(const T& value) const
00053 {return value.GetName() == fName;}
00054 private:
00055 G4String fName;
00056 };
00057
00058 }
00059
00060
00061 template <typename T>
00062 G4bool ExtractAttDef(const T& object, const G4String& name, G4AttDef& def)
00063 {
00064 const std::map<G4String, G4AttDef>* attDefs = object.GetAttDefs();
00065
00066 std::map<G4String, G4AttDef>::const_iterator iter = attDefs->find(name);
00067 if (iter == attDefs->end()) return false;
00068
00069 def = iter->second;
00070
00071 return true;
00072 }
00073
00074
00075 template <typename T>
00076 G4bool ExtractAttValue(const T& object, const G4String& name, G4AttValue& attVal)
00077 {
00078 std::vector<G4AttValue>* attValues = object.CreateAttValues();
00079
00080 std::vector<G4AttValue>::iterator iter = std::find_if(attValues->begin(), attValues->end(),
00081 HasName<G4AttValue>(name));
00082 if (iter == attValues->end()) return false;
00083
00084 attVal = *iter;
00085
00086
00087 delete attValues;
00088
00089 return true;
00090 }
00091
00092
00093 G4TypeKey GetKey(const G4AttDef& def);
00094
00095 }
00096
00097 #endif