|
||||
File indexing completed on 2025-01-18 09:57:56
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // 0027 // Jane Tinslay September 2006 0028 // 0029 // Visualisation attribute utility functions. 0030 // 0031 #ifndef G4ATTUTILS_HH 0032 #define G4ATTUTILS_HH 0033 0034 #include "globals.hh" 0035 #include "G4AttDef.hh" 0036 #include "G4AttValue.hh" 0037 #include "G4String.hh" 0038 #include "G4TypeKey.hh" 0039 #include <map> 0040 #include <vector> 0041 0042 namespace G4AttUtils { 0043 0044 namespace { 0045 0046 // Utility class 0047 template <typename T> 0048 class HasName { 0049 public: 0050 HasName(const G4String& name): fName(name) {}; 0051 bool operator()(const T& value) const 0052 {return value.GetName() == fName;} 0053 private: 0054 G4String fName; 0055 }; 0056 0057 } 0058 0059 // Extract attribute definition with given name 0060 template <typename T> 0061 G4bool ExtractAttDef(const T& object, const G4String& name, G4AttDef& def) 0062 { 0063 const std::map<G4String, G4AttDef>* attDefs = object.GetAttDefs(); 0064 0065 // NOLINTNEXTLINE(modernize-use-auto): Explicitly want a const_iterator despite attDefs being const 0066 std::map<G4String, G4AttDef>::const_iterator iter = attDefs->find(name); 0067 if (iter == attDefs->end()) return false; 0068 0069 def = iter->second; 0070 0071 return true; 0072 } 0073 0074 // Extract attribute value with given name 0075 template <typename T> 0076 G4bool ExtractAttValue(const T& object, const G4String& name, G4AttValue& attVal) 0077 { 0078 std::vector<G4AttValue>* attValues = object.CreateAttValues(); 0079 0080 auto iter = std::find_if(attValues->cbegin(), attValues->cend(), 0081 HasName<G4AttValue>(name)); 0082 if (iter == attValues->cend()) return false; 0083 0084 attVal = *iter; 0085 0086 // Clean up 0087 delete attValues; 0088 0089 return true; 0090 } 0091 0092 // Get G4TypeKey information for old style G4AttDef's 0093 G4TypeKey GetKey(const G4AttDef& def); 0094 0095 } 0096 0097 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |