Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafApplication.h
1 // ##################################################################################################
2 //
3 // Caffa Toolkit
4 // Copyright (C) Kontur AS
5 //
6 // This library may be used under the terms of either the GNU General Public License or
7 // the GNU Lesser General Public License as follows:
8 //
9 // GNU General Public License Usage
10 // This library is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
16 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 // FITNESS FOR A PARTICULAR PURPOSE.
18 #pragma once
19 
20 #include <nlohmann/json.hpp>
21 
22 #include <list>
23 #include <set>
24 #include <string>
25 
30 namespace caffa
31 {
32 class Document;
33 
38 struct AppInfo
39 {
46  enum class AppCapability : unsigned int
47  {
48  CONSOLE = 0x00,
49  SERVER = 0x01,
50  CLIENT = 0x02,
51  GUI = 0x04
52  };
53 
58  std::string name;
78  unsigned int appType;
79 
87  bool hasCapability( AppCapability typeToCheck ) const
88  {
89  return ( appType & static_cast<unsigned int>( typeToCheck ) ) != 0u;
90  }
91 
97  std::string version_string() const
98  {
99  return std::to_string( majorVersion ) + "." + std::to_string( minorVersion ) + "." + std::to_string( patchVersion );
100  }
101 };
102 
103 void to_json( nlohmann::json& jsonValue, const AppInfo& appInfo );
104 void from_json( const nlohmann::json& jsonValue, AppInfo& appInfo );
105 
107 {
108 public:
109  Application( unsigned int capabilities );
110  Application( AppInfo::AppCapability capability );
111  virtual ~Application();
112 
113  virtual std::string name() const = 0;
114  bool hasCapability( AppInfo::AppCapability typeToCheck ) const;
115  AppInfo appInfo() const;
116 
117  virtual int majorVersion() const = 0;
118  virtual int minorVersion() const = 0;
119  virtual int patchVersion() const = 0;
120 
121  static Application* instance();
122  static void registerInstance( Application* instance );
123 
124  static void assertCapability( AppInfo::AppCapability typeToAssert );
125 
126 private:
127  static Application* s_instance;
128 
129  unsigned int m_capabilities;
130 };
131 
132 } // namespace caffa
Definition: cafApplication.h:107
Main Caffa namespace.
Definition: __init__.py:1
Basic Application Information.
Definition: cafApplication.h:39
std::string name
The name of the application.
Definition: cafApplication.h:58
AppCapability
Application capability Defines what type of application it is. These flags can be combined....
Definition: cafApplication.h:47
@ CONSOLE
Console Application.
int minorVersion
Minor version number.
Definition: cafApplication.h:68
unsigned int appType
Application type. Can be CONSOLE, SERVER, CLIENT, GUI.
Definition: cafApplication.h:78
bool hasCapability(AppCapability typeToCheck) const
Check if the application has the specified capability.
Definition: cafApplication.h:87
int patchVersion
Patch version number.
Definition: cafApplication.h:73
int majorVersion
Major version number.
Definition: cafApplication.h:63
std::string version_string() const
Construct a full X.Y.Z version string with major, minor and patch version.
Definition: cafApplication.h:97