Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/JANA/JFactoryGenerator.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #pragma once
0006 
0007 #include <vector>
0008 #include <JANA/JFactorySet.h>
0009 
0010 class JApplication;
0011 
0012 class JFactoryGenerator {
0013 
0014     std::string m_plugin_name;
0015     JApplication* m_app;
0016 
0017 public:
0018 
0019     virtual ~JFactoryGenerator() = default;
0020 
0021     virtual void GenerateFactories(JFactorySet *factory_set) = 0;
0022 
0023     inline std::string GetPluginName() {
0024         return m_plugin_name;
0025     }
0026 
0027     inline void SetPluginName(std::string plugin_name) {
0028         m_plugin_name = std::move(plugin_name);
0029     }
0030 
0031     inline void SetApplication(JApplication* app) {
0032         m_app = app;
0033     }
0034 
0035     inline JApplication* GetApplication() {
0036         return m_app;
0037     }
0038 };
0039 
0040 /// JFactoryGeneratorT works for both JFactories and JMultifactories
0041 template<class T>
0042 class JFactoryGeneratorT : public JFactoryGenerator {
0043 
0044     std::string m_tag;
0045     bool m_tag_specified;
0046 
0047 public:
0048 
0049     JFactoryGeneratorT() : m_tag_specified(false) {}
0050     explicit JFactoryGeneratorT(std::string tag) : m_tag(std::move(tag)), m_tag_specified(true) {};
0051 
0052     void GenerateFactories(JFactorySet *factory_set) override {
0053         auto* factory = new T;
0054 
0055         if (m_tag_specified) {
0056             // If user specified a tag via the generator (even the empty tag!), use that.
0057             // Otherwise, use whatever tag the factory may have set for itself.
0058             factory->SetTag(m_tag);
0059         }
0060         factory->SetTypeName(JTypeInfo::demangle<T>());
0061         factory->SetPluginName(GetPluginName());
0062         factory->SetApplication(GetApplication());
0063         factory->SetLogger(GetApplication()->GetJParameterManager()->GetLogger(factory->GetPrefix()));
0064         factory_set->Add(factory);
0065     }
0066 };
0067 
0068 
0069