coral
A C++ library for distributed co-simulation
importer.hpp
Go to the documentation of this file.
1 
10 #ifndef CORAL_FMI_IMPORTER_HPP
11 #define CORAL_FMI_IMPORTER_HPP
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 
17 #include <boost/filesystem.hpp>
18 
19 #include <coral/config.h>
21 
22 
23 // Forward declarations to avoid external dependency on FMI Library.
24 struct fmi_xml_context_t;
25 typedef fmi_xml_context_t fmi_import_context_t;
26 struct jm_callbacks;
27 
28 
29 namespace coral
30 {
31 namespace fmi
32 {
33 
34 class FMU;
35 
36 
56 class Importer : public std::enable_shared_from_this<Importer>
57 {
58 public:
69  const boost::filesystem::path& cachePath);
70 
79 
80 private:
81  // Private constructors, to force use of factory functions.
82  Importer(const boost::filesystem::path& cachePath);
84 
85 public:
100  std::shared_ptr<FMU> Import(const boost::filesystem::path& fmuPath);
101 
108  void CleanCache();
109 
112 
114  fmi_import_context_t* FmilibHandle() const;
115 
116 private:
117  void PrunePtrCaches();
118 
119  // Note: The order of these declarations is important!
120  std::unique_ptr<coral::util::TempDir> m_tempCacheDir; // Only used when no cache dir is given
121  std::unique_ptr<jm_callbacks> m_callbacks;
123 
124  boost::filesystem::path m_fmuDir;
125  boost::filesystem::path m_workDir;
126 
129 };
130 
131 
132 }} // namespace
133 #endif // header guard
void CleanCache()
Removes unused files and directories from the FMU cache.
An RAII object that creates a unique directory on construction and recursively deletes it again on de...
Definition: filesystem.hpp:27
STL class.
static std::shared_ptr< Importer > Create()
Creates a new FMU importer that uses a temporary cache directory.
STL class.
fmi_import_context_t * FmilibHandle() const
Returns a pointer to the underlying FMI Library import context.
Imports and caches FMUs.
Definition: importer.hpp:56
std::string LastErrorMessage()
Returns the last FMI Library error message.
Definition: variable_io.hpp:28
Filesystem utilities.
std::shared_ptr< FMU > Import(const boost::filesystem::path &fmuPath)
Imports and loads an FMU.