22 #include "../../cpp_simshell/common/InstallDirs.h"
23 #include "../workspace/WorkspaceFactory.h"
35 SimShell::Ws::IProject::FileIterator
36 CliWorkspaceManager::CreateLeaf(
37 const shared_ptr<SimShell::Ws::IProject>& project,
38 const string& ref_file_path,
const string& file)
40 QFile::copy(QString::fromStdString(ref_file_path),
41 QString::fromStdString(project->GetPath() +
'/' + file));
42 const auto it = project->Add(file);
44 assert((it != project->end()) &&
"Iterator cannot be end().");
48 SimShell::Ws::IWorkspace::ProjectIterator
49 CliWorkspaceManager::CreateProject(
50 const shared_ptr<SimShell::Ws::IWorkspace>& workspace,
const string& name)
52 const auto it = workspace->New(
"project", name);
54 assert( (it != workspace->end()) &&
"Project iterator cannot be end().");
58 shared_ptr<Ws::CliWorkspace>
59 CliWorkspaceManager::CreateWorkspace(
const string& base_path,
const string& workspace)
61 const string workspace_path = (base_path ==
"") ? workspace : base_path +
"/" + workspace;
62 shared_ptr<Ws::CliWorkspace> ws_ptr;
64 if (!QDir(QString::fromStdString(workspace_path)).exists()) {
65 QDir(QString::fromStdString(base_path)).mkdir(QString::fromStdString(workspace));
67 Ws::CliWorkspace::Init(workspace_path);
68 ws_ptr = make_shared<Ws::CliWorkspace>(workspace_path);
70 assert((ws_ptr !=
nullptr) &&
"Workspace pointer cannot be nullptr.");
74 SimShell::Ws::IProject::FileIterator
75 CliWorkspaceManager::OpenLeaf(
76 shared_ptr<SimShell::Ws::IProject> project,
const string& file,
77 bool create_if_not_exists, std::shared_ptr<SimShell::Ws::IFile> ref_file)
79 assert((project !=
nullptr) &&
"Project cannot be nullptr.");
80 assert((ref_file !=
nullptr) &&
"reference file cannot be nullptr.");
82 SimShell::Ws::IProject::FileIterator it = project->Find(file);
84 if (it == project->end()) {
85 if (create_if_not_exists) {
86 it = CreateLeaf(project, ref_file->GetPath(), file);
90 assert((it != project->end()) &&
"File iterator cannot be end().");
94 SimShell::Ws::IProject::FileIterator
95 CliWorkspaceManager::OpenLeaf(
96 shared_ptr<SimShell::Ws::IProject> project,
const string& file,
97 bool create_if_not_exists,
98 const string& ref_ws_path,
const string& ref_project,
const string& ref_file)
100 assert((project !=
nullptr) &&
"project cannot be nullptr.");
102 SimShell::Ws::IProject::FileIterator it = project->Find(file);
104 if (it == project->end()) {
105 if (create_if_not_exists) {
107 it = CreateLeaf(project,
108 ws_template.Get(ref_project)->Get(ref_file)->GetPath(), file);
112 assert((it != project->end()) &&
"Leaf iterator cannot be end().");
116 SimShell::Ws::IWorkspace::ProjectIterator
117 CliWorkspaceManager::OpenProject(
118 shared_ptr<CliWorkspace> workspace,
const string& project,
119 bool create_if_not_exists)
121 SimShell::Ws::IWorkspace::ProjectIterator it = workspace->Find(project);
123 if (it == workspace->end()) {
124 if (create_if_not_exists) {
125 it = CreateProject(workspace, project);
128 assert((it != workspace->end()) &&
"Project iterator cannot be end().");
132 shared_ptr<CliWorkspace>
133 CliWorkspaceManager::OpenWorkspace(
134 const string& base_path,
const string& workspace,
135 bool create_if_not_exists)
137 const string workspace_path = (base_path ==
"") ? workspace : base_path +
"/" + workspace;
138 shared_ptr<CliWorkspace> ws_ptr;
140 if (!QDir(QString::fromStdString(workspace_path)).exists()
141 || !QFile::exists(QString::fromStdString(workspace_path+
"/" + WorkspaceFactory::g_workspace_index_file))) {
142 if (create_if_not_exists) {
143 ws_ptr = CreateWorkspace(base_path, workspace);
146 ws_ptr = make_shared<CliWorkspace>(workspace_path);
149 assert((ws_ptr !=
nullptr) &&
"Workspace pointer cannot be nullptr.");
Namespace for SimPT shell package.
Cli Workspace for the command-line simulator.
Namespace for generic graphical shell for simulators.
Namespace for SimPT specific workspace classes.
Interface for CliWorkspaceManager.