Overte C++ Documentation
Conditional.h
1 //
2 // Created by Bradley Austin Davis 2015/10/20
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_Controllers_Conditional_h
11 #define hifi_Controllers_Conditional_h
12 
13 #include <list>
14 #include <memory>
15 
16 #include <QtCore/QString>
17 
18 #include <shared/Factory.h>
19 
20 class QJsonValue;
21 
22 namespace controller {
23  /*
24  * encapsulates a source, destination and filters to apply
25  */
26  class Conditional {
27  public:
28  using Pointer = std::shared_ptr<Conditional>;
29  using List = std::list<Pointer>;
30  using Factory = hifi::SimpleFactory<Conditional, QString>;
31  using Lambda = std::function<bool()>;
32 
33  virtual ~Conditional() = default;
34 
35  virtual bool satisfied() = 0;
36  virtual bool parseParameters(const QJsonValue& parameters) { return true; }
37 
38  static Pointer parse(const QJsonValue& json);
39  static void registerBuilder(const QString& name, Factory::Builder builder);
40  static Factory& getFactory() { return _factory; }
41  protected:
42  static Factory _factory;
43  };
44 
45 }
46 
47 #define REGISTER_CONDITIONAL_CLASS(classEntry) \
48  private: \
49  using Registrar = Conditional::Factory::Registrar<classEntry>; \
50  static Registrar _registrar;
51 
52 #define REGISTER_CONDITIONAL_CLASS_INSTANCE(classEntry, className) \
53  classEntry::Registrar classEntry::_registrar(className, Conditional::getFactory());
54 
55 
56 #endif