Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:22:22

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