VPTissue Reference Manual
IWorkspace.h
Go to the documentation of this file.
1 #ifndef WS_IWORKSPACE_H_INCLUDED
2 #define WS_IWORKSPACE_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "IPreferences.h"
23 #include "IUserData.h"
25 #include "event/WorkspaceChanged.h"
26 #include "util/misc/Subject.h"
27 
28 #include <boost/property_tree/ptree.hpp>
29 #include <map>
30 
31 namespace SimShell {
32 namespace Ws {
33 
34 class IProject;
35 class IWorkspace;
36 
48 class IWorkspace : public virtual IPreferences,
49  public IUserData,
50  public SimPT_Sim::Util::Subject<Event::WorkspaceChanged, std::weak_ptr<const void>>
51 {
52 public:
54  virtual ~IWorkspace() {}
55 
57  public:
58  ProjectMapEntry(const std::shared_ptr<IProject>& p, const std::string& t)
59  : m_project(p), m_type(t) {}
60 
61  inline IProject* operator->() { return m_project.get(); }
62  inline const IProject* operator->() const { return m_project.get(); }
63 
64  inline IProject& operator*() { return *m_project.get(); }
65  inline const IProject& operator*() const { return *m_project.get(); }
66 
67  inline std::shared_ptr<const IProject> Project() const { return m_project; }
68  inline std::shared_ptr<IProject> Project() { return m_project; }
69 
70  inline std::string Type() { return m_type; }
71 
72  private:
73  std::shared_ptr<IProject> m_project;
74  std::string m_type;
75  };
76 
77  using ProjectMap = std::map<std::string, ProjectMapEntry>;
78  using ProjectIterator = typename ProjectMap::iterator;
79  using ConstProjectIterator = typename ProjectMap::const_iterator ;
80 
86  virtual ProjectIterator Add(const std::string& type, const std::string& name) = 0;
87 
90  virtual std::shared_ptr<IProject> Back() = 0;
91 
94  virtual std::shared_ptr<const IProject> Back() const = 0;
95 
97  virtual ProjectIterator begin() = 0;
98 
100  virtual ConstProjectIterator begin() const = 0;
101 
104  virtual std::shared_ptr<IProject> Front() = 0;
105 
108  virtual std::shared_ptr<const IProject> Front() const = 0;
109 
111  virtual ProjectIterator end() = 0;
112 
114  virtual ConstProjectIterator end() const = 0;
115 
118  virtual ProjectIterator Find(const std::string& name) = 0;
119 
122  virtual ConstProjectIterator Find(const std::string& name) const = 0;
123 
126  virtual bool IsProject(const std::string& name) const = 0;
127 
130  virtual std::shared_ptr<IProject> Get(const std::string& name) = 0;
131 
134  virtual std::shared_ptr<const IProject> Get(const std::string& name) const = 0;
135 
137  virtual const std::string& GetIndexFile() const = 0;
138 
140  virtual const std::string& GetPath() const = 0;
141 
146  virtual ProjectIterator New(const std::string& type, const std::string& name) = 0;
147 
150  virtual void Refresh() = 0;
151 
154  virtual void Remove(ProjectIterator it) = 0;
155 
158  virtual void Remove(const std::string& name) = 0;
159 
162  virtual ProjectIterator Rename(ProjectIterator, const std::string& new_name) = 0;
163 
166  virtual ProjectIterator Rename(const std::string& old_name, const std::string& new_name) = 0;
167 };
168 
169 } // namespace
170 } // namespace
171 
172 #endif // end_of_inclde_guard
virtual ProjectIterator begin()=0
Get iterator pointing to first project.
virtual const std::string & GetIndexFile() const =0
Get name of index file for this type of workspace.
virtual std::shared_ptr< IProject > Front()=0
Get first project.
Interface for project-like behavior.
Definition: IProject.h:59
Interface for IUserData.
virtual ProjectIterator Find(const std::string &name)=0
Get iterator to project with given name.
Abstraction of project in workspace on file system.
virtual ProjectIterator Add(const std::string &type, const std::string &name)=0
Add existing project to workspace.
virtual void Refresh()=0
Refresh workspace.
virtual ~IWorkspace()
Virtual destructor.
Definition: IWorkspace.h:54
virtual const std::string & GetPath() const =0
Get path workspace was initialized with.
virtual ProjectIterator end()=0
Get iterator pointing to one position after last project.
Interface for workspace-like behavior.
Definition: IWorkspace.h:48
Interface/Implementation of Subject.
Definition for WorkspaceChanged.
Interface expressing the ability of an object to have a ptree of preferences stored in it...
Definition: IPreferences.h:33
virtual std::shared_ptr< IProject > Get(const std::string &name)=0
Get project with given name.
Interface that expresses the ability to have user data, i.e.
Definition: IUserData.h:29
virtual bool IsProject(const std::string &name) const =0
Get iterator to project with given name.
virtual ProjectIterator New(const std::string &type, const std::string &name)=0
Create new project in workspace.
virtual ProjectIterator Rename(ProjectIterator, const std::string &new_name)=0
Rename project.
Interface for IPreferences.
virtual std::shared_ptr< IProject > Back()=0
Get last project.
Subject in Observer pattern.
Definition: Subject.h:34
Definition for PreferencesChanged.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
virtual void Remove(ProjectIterator it)=0
Remove project.