00001
00002
00011 #ifndef ATHCONTAINERS_AUXTYPEREGISTRY_H
00012 #define ATHCONTAINERS_AUXTYPEREGISTRY_H
00013
00014
00015 #include "AthContainersInterfaces/AuxTypes.h"
00016 #include "AthContainersInterfaces/IAuxTypeVector.h"
00017 #include "AthContainersInterfaces/IAuxTypeVectorFactory.h"
00018 #include "AthContainers/tools/AuxTypeVector.h"
00019 #include "AthContainers/tools/AuxTypeVectorFactory.h"
00020 #include "AthContainers/tools/threading.h"
00021 #include <cstddef>
00022 #include <typeinfo>
00023 #include <vector>
00024
00025
00026 #if __cplusplus < 201100
00027 # include "CxxUtils/unordered_map.h"
00028 namespace SG_STD_OR_SG = SG;
00029 #else
00030 # include <unordered_map>
00031 # include <functional>
00032 namespace SG_STD_OR_SG = std;
00033 #endif
00034
00035
00036 namespace SG {
00037
00038
00071 class AuxTypeRegistry
00072 {
00073 public:
00074 typedef AthContainers_detail::upgrade_mutex mutex_t;
00075 typedef AthContainers_detail::strict_shared_lock<AuxTypeRegistry> lock_t;
00076 typedef AthContainers_detail::upgrading_lock<mutex_t> upgrading_lock_t;
00077
00081 static AuxTypeRegistry& instance();
00082
00083
00093 template <class T>
00094 SG::auxid_t getAuxID (const std::string& name,
00095 const std::string& clsname = "");
00096
00097
00110 SG::auxid_t getAuxID (const std::type_info& ti,
00111 const std::string& name,
00112 const std::string& clsname = "");
00113
00114
00124 SG::auxid_t findAuxID( const std::string& name,
00125 const std::string& clsname = "" ) const;
00126
00127
00134 IAuxTypeVector* makeVector (SG::auxid_t auxid,
00135 size_t size,
00136 size_t capacity) const;
00137
00138
00146 IAuxTypeVector* makeVector (lock_t& lock,
00147 SG::auxid_t auxid,
00148 size_t size,
00149 size_t capacity) const;
00150
00151
00156 std::string getName (SG::auxid_t auxid) const;
00157
00158
00164 std::string getName (lock_t& lock,
00165 SG::auxid_t auxid) const;
00166
00167
00173 std::string getClassName (SG::auxid_t auxid) const;
00174
00175
00182 std::string getClassName (lock_t& lock,
00183 SG::auxid_t auxid) const;
00184
00185
00190 const std::type_info* getType (SG::auxid_t auxid) const;
00191
00192
00198 const std::type_info* getType (lock_t& lock,
00199 SG::auxid_t auxid) const;
00200
00201
00208 std::string getTypeName (SG::auxid_t auxid) const;
00209
00210
00218 std::string getTypeName (lock_t& lock,
00219 SG::auxid_t auxid) const;
00220
00221
00226 const std::type_info* getVecType (SG::auxid_t auxid) const;
00227
00228
00235 const std::type_info* getVecType (lock_t& lock,
00236 SG::auxid_t auxid) const;
00237
00238
00245 std::string getVecTypeName (SG::auxid_t auxid) const;
00246
00247
00256 std::string getVecTypeName (lock_t& lock,
00257 SG::auxid_t auxid) const;
00258
00259
00264 size_t getEltSize (SG::auxid_t auxid) const;
00265
00266
00273 size_t getEltSize (lock_t& lock,
00274 SG::auxid_t auxid) const;
00275
00276
00287 void copy (SG::auxid_t auxid,
00288 void* dst, size_t dst_index,
00289 const void* src, size_t src_index);
00290
00291
00303 void copy (lock_t& lock,
00304 SG::auxid_t auxid,
00305 void* dst, size_t dst_index,
00306 const void* src, size_t src_index);
00307
00308
00320 void copyForOutput (SG::auxid_t auxid,
00321 void* dst, size_t dst_index,
00322 const void* src, size_t src_index);
00323
00324
00337 void copyForOutput (lock_t& lock,
00338 SG::auxid_t auxid,
00339 void* dst, size_t dst_index,
00340 const void* src, size_t src_index);
00341
00342
00353 void swap (SG::auxid_t auxid,
00354 void* a, size_t aindex,
00355 void* b, size_t bindex);
00356
00357
00369 void swap (lock_t& lock,
00370 SG::auxid_t auxid,
00371 void* a, size_t aindex,
00372 void* b, size_t bindex);
00373
00374
00381 void clear (SG::auxid_t auxid, void* dst, size_t dst_index);
00382
00383
00391 void clear (lock_t& lock,
00392 SG::auxid_t auxid, void* dst, size_t dst_index);
00393
00394
00402 const IAuxTypeVectorFactory* getFactory (const std::type_info& ti) const;
00403
00404
00414 const IAuxTypeVectorFactory* getFactory (lock_t& lock,
00415 const std::type_info& ti) const;
00416
00417
00427 const IAuxTypeVectorFactory* getFactory (upgrading_lock_t& lock,
00428 const std::type_info& ti) const;
00429
00430
00441 void addFactory (const std::type_info& ti, IAuxTypeVectorFactory* factory);
00442
00443
00447 void lock_shared() const;
00448
00449
00453 void unlock_shared() const;
00454
00455
00456 private:
00462 AuxTypeRegistry();
00463
00464
00470 ~AuxTypeRegistry();
00471
00472
00474 AuxTypeRegistry (const AuxTypeRegistry&);
00475 AuxTypeRegistry& operator= (const AuxTypeRegistry&);
00476
00477
00497 SG::auxid_t
00498 findAuxID (const std::string& name,
00499 const std::string& clsname,
00500 const std::type_info& ti,
00501 IAuxTypeVectorFactory* (AuxTypeRegistry::*makeFactory) () const);
00502
00503
00512 const IAuxTypeVectorFactory* getFactoryLocked (const std::type_info& ti) const;
00513
00514
00522 const IAuxTypeVectorFactory* getFactory (SG::auxid_t auxid) const;
00523
00524
00533 const IAuxTypeVectorFactory* getFactory (lock_t& ,
00534 SG::auxid_t auxid) const;
00535
00536
00548 void addFactory (upgrading_lock_t& lock,
00549 const std::type_info& ti,
00550 IAuxTypeVectorFactory* factory);
00551
00552
00559 template <class T>
00560 IAuxTypeVectorFactory* makeFactory() const;
00561
00562
00569 IAuxTypeVectorFactory* makeFactoryNull() const;
00570
00571
00579 void setELFlags (upgrading_lock_t& lock, auxid_t auxid);
00580
00581
00588 void applyELThinning (void* dst);
00589
00590
00597 void applyELVecThinning (void* dst);
00598
00599
00601 struct typeinfo_t
00602 {
00604 const IAuxTypeVectorFactory* m_factory;
00605
00607 const std::type_info* m_ti;
00608
00610 std::string m_name;
00611
00613 std::string m_clsname;
00614 };
00615
00616
00618 std::vector<typeinfo_t> m_types;
00619
00620
00623 typedef std::pair<std::string, std::string> key_t;
00624
00625
00627 struct stringpair_hash
00628 {
00629 size_t operator() (const key_t& key) const
00630 {
00631 return shash (key.first) + shash (key.second);
00632 }
00633 SG_STD_OR_SG::hash<std::string> shash;
00634 };
00635
00636
00637 #ifndef __REFLEX__
00638
00639
00640
00641
00642
00644 typedef SG_STD_OR_SG::unordered_map<key_t, SG::auxid_t, stringpair_hash>
00645 id_map_t;
00646 id_map_t m_auxids;
00647
00649 typedef SG_STD_OR_SG::unordered_map<const std::type_info*,
00650 const IAuxTypeVectorFactory*> ti_map_t;
00651 ti_map_t m_factories;
00652 #endif
00653
00655 std::vector<const IAuxTypeVectorFactory*> m_oldFactories;
00656
00659 mutable mutex_t m_mutex;
00660
00664 std::vector<bool> m_isEL;
00665
00669 std::vector<bool> m_isELVec;
00670 };
00671
00672
00673 }
00674
00675
00676 #include "AthContainers/AuxTypeRegistry.icc"
00677
00678
00679 #endif // not ATHCONTAINERS_AUXTYPEREGISTRY_H