Radium Engine  1.5.0
ShaderConfigFactory.cpp
1 #include <Engine/Data/ShaderConfigFactory.hpp>
2 
3 #include <map>
4 
5 #include <Core/Utils/Log.hpp>
6 
7 namespace Ra {
8 namespace Engine {
9 namespace Data {
10 namespace ShaderConfigurationFactory {
11 
12 using namespace Core::Utils; // log
13 
14 static std::map<std::string, ShaderConfiguration> configs;
15 
16 void addConfiguration( const ShaderConfiguration& config ) {
17  if ( config.getName().empty() ) {
18  LOG( logWARNING ) << "Empty name in ShaderConfigurationFactory::addConfiguration call. "
19  "Configuration not added";
20  return;
21  }
22 
23  auto found = configs.insert( { config.getName(), config } );
24  if ( !found.second ) {
25  LOG( logDEBUG ) << "Configuration " << config.getName()
26  << " already in ShaderConfigurationFactory. "
27  "Configuration not added";
28  return;
29  }
30 }
31 
32 bool removeConfiguration( const std::string& configName ) {
33  auto found = configs.find( configName );
34  if ( found != configs.end() ) {
35  configs.erase( found );
36  return true;
37  }
38  return false;
39 }
40 
41 Core::Utils::optional<ShaderConfiguration> getConfiguration( const std::string& name ) {
42  if ( name.empty() ) {
43  LOG( logWARNING ) << "Empty name in ShaderConfigurationFactory::getConfiguration call.";
44  return {};
45  }
46 
47  auto found = configs.find( name );
48  if ( found != configs.end() ) { return found->second; }
49  else { return {}; }
50 }
51 
52 } // namespace ShaderConfigurationFactory
53 } // namespace Data
54 } // namespace Engine
55 } // namespace Ra
void addConfiguration(const ShaderConfiguration &config)
Core::Utils::optional< ShaderConfiguration > getConfiguration(const std::string &name)
bool removeConfiguration(const std::string &configName)
Definition: Cage.cpp:3