OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
Scope.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenModelica.
3  *
4  * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
5  * c/o Linköpings universitet, Department of Computer and Information Science,
6  * SE-58183 Linköping, Sweden.
7  *
8  * All rights reserved.
9  *
10  * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
11  * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12  * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13  * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14  * ACCORDING TO RECIPIENTS CHOICE.
15  *
16  * The OpenModelica software and the Open Source Modelica
17  * Consortium (OSMC) Public License (OSMC-PL) are obtained
18  * from OSMC, either from the above address,
19  * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20  * http://www.openmodelica.org, and in the OpenModelica distribution.
21  * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22  *
23  * This program is distributed WITHOUT ANY WARRANTY; without
24  * even the implied warranty of MERCHANTABILITY or FITNESS
25  * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26  * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27  *
28  * See the full OSMC Public License conditions for more details.
29  *
30  */
31 
32 #ifndef _OMS_SCOPE_H_
33 #define _OMS_SCOPE_H_
34 
35 #include "ComRef.h"
36 #include "Model.h"
37 #include "OMSimulator/Types.h"
38 
39 #include <map>
40 #include <string>
41 #include <vector>
42 
43 namespace oms
44 {
45  class Scope
46  {
47  private:
48  Scope();
49  ~Scope();
50 
51  // stop the compiler generating methods copying the object
52  Scope(Scope const&);
53  Scope& operator=(Scope const&);
54 
55  public:
60  static Scope& GetInstance();
61 
62  Model* newModel(const ComRef& cref);
63  oms_status_enu_t deleteModel(const ComRef& cref);
64  oms_status_enu_t renameModel(const ComRef& cref, const ComRef& newCref);
65  oms_status_enu_t exportModel(const ComRef& cref, const std::string& filename);
66  oms_status_enu_t importModel(const std::string& filename, char** cref);
67  oms_status_enu_t setTempDirectory(const std::string& newTempDir);
68  oms_status_enu_t setWorkingDirectory(const std::string& newWorkingDir);
69  oms_status_enu_t getElement(const ComRef& cref, oms::Element** element);
70  oms_status_enu_t getElements(const ComRef& cref, oms::Element*** elements);
71  Model* getModel(const ComRef& cref);
72 
73  oms_status_enu_t loadSnapshot(const ComRef& cref, const char* snapshot, char** newCref);
74  oms_status_enu_t importSnapshot(const ComRef& cref, const char* snapshot, char** newCref);
75 
76  const std::string& getTempDirectory() const {return GetInstance().tempDir;}
77  std::string getWorkingDirectory();
78 
79  protected:
80  static oms_status_enu_t miniunz(const std::string& filename, const std::string& extractdir);
81 
82  private:
83  std::vector<Model*> models;
84  std::map<ComRef, unsigned int> models_map;
85 
86  std::string tempDir;
87  };
88 }
89 
90 #endif
oms
Definition: AlgLoop.h:44
System.h
oms::Scope::renameModel
oms_status_enu_t renameModel(const ComRef &cref, const ComRef &newCref)
Definition: Scope.cpp:109
oms::XercesValidator::validateSSP
oms_status_enu_t validateSSP(const char *ssd, const std::string &filePath)
Definition: XercesValidator.cpp:126
oms::Scope::Scope
Scope()
Definition: Scope.cpp:43
ComRef.h
oms::Model
Definition: Model.h:52
oms::Scope::getElement
oms_status_enu_t getElement(const ComRef &cref, oms::Element **element)
Definition: Scope.cpp:355
oms::Scope::miniunz
static oms_status_enu_t miniunz(const std::string &filename, const std::string &extractdir)
Definition: Scope.cpp:145
Model.h
oms::ssp::Draft20180219::ssd::system
const char * system
Definition: Tags.cpp:57
oms::Snapshot::writeDocument
oms_status_enu_t writeDocument(char **contents)
Definition: Snapshot.cpp:412
oms::ComRef
ComRef - component reference.
Definition: ComRef.h:46
oms::Snapshot::getRootCref
oms::ComRef getRootCref() const
Definition: Snapshot.cpp:260
oms::Scope::importModel
oms_status_enu_t importModel(const std::string &filename, char **cref)
Definition: Scope.cpp:183
OMS_RECURSIVE_DIRECTORY_ITERATOR
#define OMS_RECURSIVE_DIRECTORY_ITERATOR(path)
Definition: OMSFileSystem.h:8
oms::ssp::Draft20180219::ssd::component
const char * component
Definition: Tags.cpp:45
oms::XercesValidator
Definition: XercesValidator.h:44
logError_AlreadyInScope
#define logError_AlreadyInScope(cref)
Definition: Logging.h:120
oms::Scope::setTempDirectory
oms_status_enu_t setTempDirectory(const std::string &newTempDir)
Definition: Scope.cpp:276
Snapshot.h
oms::Model::exportToFile
oms_status_enu_t exportToFile(const std::string &filename) const
Definition: Model.cpp:1020
oms::ComRef::isValidIdent
static bool isValidIdent(const std::string &ident)
Definition: ComRef.cpp:89
Tags.h
logInfo
#define logInfo(msg)
Definition: Logging.h:100
oms::Element
Element.
Definition: Element.h:49
oms::Scope::tempDir
std::string tempDir
Definition: Scope.h:86
oms::ssp::Draft20180219::ssd::elements
const char * elements
Definition: Tags.cpp:54
oms::Scope::getWorkingDirectory
std::string getWorkingDirectory()
Definition: Scope.cpp:341
oms::Scope::deleteModel
oms_status_enu_t deleteModel(const ComRef &cref)
Definition: Scope.cpp:90
oms_canonical
filesystem::path oms_canonical(const filesystem::path &p)
Definition: OMSFileSystem.cpp:103
logError_ModelNotInScope
#define logError_ModelNotInScope(cref)
Definition: Logging.h:136
oms::Scope::newModel
Model * newModel(const ComRef &cref)
Definition: Scope.cpp:70
oms::Scope::GetInstance
static Scope & GetInstance()
Definition: Scope.cpp:63
oms::Model::getTempDirectory
std::string getTempDirectory() const
Definition: Model.h:68
oms::Component
Definition: Component.h:59
oms::Snapshot::getResourceNode
pugi::xml_node getResourceNode(const filesystem::path &filename) const
Definition: Snapshot.cpp:133
naive_uncomplete
filesystem::path naive_uncomplete(const filesystem::path &path, const filesystem::path &base)
Definition: OMSFileSystem.cpp:46
logWarning
#define logWarning(msg)
Definition: Logging.h:101
oms::Model::ssdVariants
std::map< ComRef, char * > ssdVariants
list of all variants copied when user create a new variant using oms_duplicateVariant()
Definition: Model.h:138
oms::ComRef::isEmpty
bool isEmpty() const
Definition: ComRef.cpp:99
oms::Model::importedResources
std::vector< std::string > importedResources
list of imported resources from ssp
Definition: Model.h:136
oms::Model::copyResources
void copyResources(bool copy_resources)
Definition: Model.h:96
oms::Scope::~Scope
~Scope()
Definition: Scope.cpp:55
oms::Snapshot
Definition: Snapshot.h:46
oms::Model::getCref
const ComRef & getCref() const
Definition: Model.h:63
oms::Scope::getTempDirectory
const std::string & getTempDirectory() const
Definition: Scope.h:76
oms::Model::NewModel
static Model * NewModel(const ComRef &cref)
Definition: Model.cpp:82
Component.h
oms::Scope::getElements
oms_status_enu_t getElements(const ComRef &cref, oms::Element ***elements)
Definition: Scope.cpp:383
oms::Scope::getModel
Model * getModel(const ComRef &cref)
Definition: Scope.cpp:404
oms::Scope::models
std::vector< Model * > models
last element is always NULL
Definition: Scope.h:83
oms::Model::importSnapshot
oms_status_enu_t importSnapshot(const char *snapshot, char **newCref)
Definition: Model.cpp:292
Scope.h
oms::Snapshot::importResourceFile
oms_status_enu_t importResourceFile(const filesystem::path &filename, const filesystem::path &root)
Definition: Snapshot.cpp:83
oms::Scope::models_map
std::map< ComRef, unsigned int > models_map
Definition: Scope.h:84
oms::System
Definition: System.h:65
oms::Model::getElements
oms::Element ** getElements()
Definition: Model.h:99
oms::ComRef::c_str
const char * c_str() const
Definition: ComRef.h:75
logError
#define logError(msg)
Definition: Logging.h:102
oms::Scope::setWorkingDirectory
oms_status_enu_t setWorkingDirectory(const std::string &newWorkingDir)
Definition: Scope.cpp:311
oms::Scope::importSnapshot
oms_status_enu_t importSnapshot(const ComRef &cref, const char *snapshot, char **newCref)
Definition: Scope.cpp:447
oms::Model::getComponent
Component * getComponent(const ComRef &cref)
Definition: Model.cpp:375
oms::Snapshot::importResourceMemory
oms_status_enu_t importResourceMemory(const filesystem::path &filename, const char *contents)
Definition: Snapshot.cpp:95
oms::Model::getSystem
System * getSystem(const ComRef &cref)
Definition: Model.cpp:358
oms::ComRef::pop_front
ComRef pop_front()
returns the first part of the ComRef and removed it from the current object
Definition: ComRef.cpp:184
oms::Scope::exportModel
oms_status_enu_t exportModel(const ComRef &cref, const std::string &filename)
Definition: Scope.cpp:136
XercesValidator.h
Flags.h
oms::Model::importFromSnapshot
oms_status_enu_t importFromSnapshot(const Snapshot &snapshot)
Definition: Model.cpp:856
oms::Scope::operator=
Scope & operator=(Scope const &)
not implemented
oms::Flags::SuppressPath
static bool SuppressPath()
Definition: Flags.h:75
oms::Scope::loadSnapshot
oms_status_enu_t loadSnapshot(const ComRef &cref, const char *snapshot, char **newCref)
Definition: Scope.cpp:413
oms::Scope
Definition: Scope.h:45