NAP
projectinfo.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include "service.h"
8 #include <rtti/object.h>
9 #include "utility/fileutils.h"
10 
11 namespace nap
12 {
13  class ModuleManager;
14 
15  // Globals
16  namespace projectinfo
17  {
18  constexpr const char* iniDirectory = ".ini";
19  constexpr const char* iniExtension = ".ini";
20  constexpr const char* dataDir = "data";
21  }
22 
26  class NAPAPI PathMapping : public rtti::Object
27  {
28  RTTI_ENABLE(rtti::Object)
29  public:
33  const std::string& getFilename() const { return mFilename; }
34 
35  std::string mProjectExeToRoot;
36  std::string mNapkinExeToRoot;
37  std::vector<std::string> mModulePaths;
38  std::string mBuildPath;
39 
40  private:
41  std::string mFilename;
42  };
43 
44 
53  class NAPAPI ProjectInfo : public rtti::Object
54  {
55  RTTI_ENABLE(rtti::Object)
56  friend class nap::Core;
57 
58  public:
62  enum class EContext : uint8
63  {
64  Application = 0,
65  Editor = 1
66  };
67 
68  std::string mTitle;
69  std::string mVersion;
70  std::string mDefaultData;
71  std::string mPathMappingFile;
72  std::string mServiceConfigFilename = {};
73  std::vector<std::string> mRequiredModules;
74 
78  bool isEditorMode() const;
79 
83  std::string getFilename() const;
84 
88  std::string getProjectDir() const;
89 
93  std::string getNAPRootDir() const;
94 
98  std::string getBuildDir() const;
99 
103  std::vector<std::string> getModuleDirectories() const;
104 
109  std::string getDataFile() const;
110 
114  std::string getDataDirectory() const;
115 
122  std::string getIniDir() const;
123 
131  std::string getIniFilePath(const std::string& name) const;
132 
139  bool hasServiceConfigFile() const;
140 
144  const PathMapping& getPathMapping() const;
145 
160  void patchPath(std::string& path, const std::unordered_map<std::string, std::string>& additionalValues = {}) const;
161 
175  void patchPaths(std::vector<std::string>& paths, const std::unordered_map<std::string, std::string>& additionalValues = {}) const;
176 
181  std::unique_ptr<ProjectInfo> clone() const;
182 
183  private:
190  bool init(const std::string fileName, ProjectInfo::EContext context, nap::utility::ErrorState& error);
191 
192  std::unordered_map<std::string, std::string> getTemplateValues(const std::unordered_map<std::string, std::string>& additionalValues) const;
193  std::string mFilename;
194  std::unique_ptr<PathMapping> mPathMapping;
195  EContext mContext = EContext::Application;
196  std::string mRoot;
197  std::string mProjectDir;
198  };
199 
200 
204  class NAPAPI ModuleInfo : public rtti::Object
205  {
206  RTTI_ENABLE(rtti::Object)
207  friend class nap::ModuleManager;
208  public:
209  std::vector<std::string> mRequiredModules;
210  std::vector<std::string> mLibSearchPaths;
211  std::vector<std::string> mDataSearchPaths;
212 
216  std::string getFilename() const;
217 
221  std::string getDirectory() const;
222 
226  const ProjectInfo& getProjectInfo() const;
227 
228  private:
229  std::string mFilename;
230  const ProjectInfo* mProjectInfo;
231  };
232 
233 } // namespace nap
nap::ProjectInfo::mDefaultData
std::string mDefaultData
Property: 'Data' relative path to the application content (json) file.
Definition: projectinfo.h:70
nap::PathMapping::mBuildPath
std::string mBuildPath
Relative path to the build output directory.
Definition: projectinfo.h:38
nap::PathMapping::mProjectExeToRoot
std::string mProjectExeToRoot
Relative path from project to executable.
Definition: projectinfo.h:35
nap::projectinfo::iniExtension
constexpr const char * iniExtension
.ini file extension, used to (re)-store module specific settings in between sessions
Definition: projectinfo.h:19
nap::uint8
uint8_t uint8
Definition: numeric.h:16
nap::rtti::Object
Definition: object.h:30
nap::ProjectInfo::mVersion
std::string mVersion
Property: 'Version' project version.
Definition: projectinfo.h:69
nap::utility::ErrorState
Definition: errorstate.h:19
nap::ProjectInfo::EContext
EContext
Definition: projectinfo.h:62
nap::projectinfo::dataDir
constexpr const char * dataDir
Default data directory.
Definition: projectinfo.h:20
nap::PathMapping::mNapkinExeToRoot
std::string mNapkinExeToRoot
Relative path from napkin to executable.
Definition: projectinfo.h:36
nap::Core
Definition: core.h:82
nap::PathMapping
Definition: projectinfo.h:26
nap::ProjectInfo::mRequiredModules
std::vector< std::string > mRequiredModules
Property: 'RequiredModules' names of modules this project depends on.
Definition: projectinfo.h:73
nap::ProjectInfo::mTitle
std::string mTitle
Property: 'Title' project title.
Definition: projectinfo.h:68
nap::projectinfo::iniDirectory
constexpr const char * iniDirectory
.ini directory, holds files used to (re)-store module specific settings in between sessions
Definition: projectinfo.h:18
nap::ModuleManager
Definition: modulemanager.h:86
nap::ModuleInfo
Definition: projectinfo.h:204
nap::ProjectInfo::mPathMappingFile
std::string mPathMappingFile
Property: 'PathMapping' relative path to the path mapping file.
Definition: projectinfo.h:71
nap
Definition: templateapp.h:17
nap::ProjectInfo
Definition: projectinfo.h:53
nap::PathMapping::mModulePaths
std::vector< std::string > mModulePaths
Relative paths to the module directories.
Definition: projectinfo.h:37
nap::PathMapping::getFilename
const std::string & getFilename() const
Definition: projectinfo.h:33