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  SERVER,
49  CLIENT
50  };
51 
56  std::string name;
76  unsigned int appType;
77 
81  std::string description;
82 
86  std::string contactEmail;
87 
95  bool hasCapability( AppCapability typeToCheck ) const
96  {
97  return ( appType & static_cast<unsigned int>( typeToCheck ) ) != 0u;
98  }
99 
105  std::string version_string() const
106  {
107  return std::to_string( majorVersion ) + "." + std::to_string( minorVersion ) + "." + std::to_string( patchVersion );
108  }
109 
110  static nlohmann::json jsonSchema();
111 };
112 
113 void to_json( nlohmann::json& jsonValue, const AppInfo& appInfo );
114 void from_json( const nlohmann::json& jsonValue, AppInfo& appInfo );
115 
117 {
118 public:
119  Application( unsigned int capabilities );
120  Application( AppInfo::AppCapability capability );
121  virtual ~Application();
122 
123  virtual std::string name() const = 0;
124  bool hasCapability( AppInfo::AppCapability typeToCheck ) const;
125  AppInfo appInfo() const;
126 
127  virtual int majorVersion() const = 0;
128  virtual int minorVersion() const = 0;
129  virtual int patchVersion() const = 0;
130  virtual std::string description() const = 0;
131  virtual std::string contactEmail() const = 0;
132 
133  static Application* instance();
134  static void registerInstance( Application* instance );
135 
136  static void assertCapability( AppInfo::AppCapability typeToAssert );
137 
138 private:
139  static Application* s_instance;
140 
141  unsigned int m_capabilities;
142 };
143 
144 } // namespace caffa
AppCapability
Application capability Defines what type of application it is. These flags can be combined...
Definition: cafApplication.h:46
int patchVersion
Patch version number.
Definition: cafApplication.h:71
int majorVersion
Major version number.
Definition: cafApplication.h:61
std::string name
The name of the application.
Definition: cafApplication.h:56
bool hasCapability(AppCapability typeToCheck) const
Check if the application has the specified capability.
Definition: cafApplication.h:95
Definition: cafApplication.h:116
Basic Application Information.
Definition: cafApplication.h:38
std::string contactEmail
Contact email.
Definition: cafApplication.h:86
unsigned int appType
Application type. Can be CONSOLE, SERVER, CLIENT, GUI.
Definition: cafApplication.h:76
int minorVersion
Minor version number.
Definition: cafApplication.h:66
std::string description
Application description.
Definition: cafApplication.h:81
Definition: cafDocument.h:35
Main Caffa namespace.
Definition: cafApplication.h:30
std::string version_string() const
Construct a full X.Y.Z version string with major, minor and patch version.
Definition: cafApplication.h:105