VPTissue Reference Manual
FileExploration.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "FileExploration.h"
21 
22 using boost::property_tree::ptree;
23 using namespace std;
24 
25 namespace SimPT_Parex {
26 
27 FileExploration::FileExploration(const string& name, const vector<pair<string, ptree>>& files, const ptree& preferences)
28  : Exploration(name, preferences)
29 {
30  for (const auto& pair : files) {
31  m_file_names.push_back(pair.first);
32  m_file_contents.push_back(pair.second);
33  }
34 }
35 
36 FileExploration::FileExploration(const ptree& pt)
37  : Exploration(pt)
38 {
39  ReadPtree(pt);
40 }
41 
42 FileExploration::FileExploration(const FileExploration& other)
43  : Exploration(other), m_file_names(other.m_file_names), m_file_contents(other.m_file_contents)
44 {
45 }
46 
48 {
49  if (this != &other) {
50  this->operator=(other);
51 
52  m_file_names = other.m_file_names;
53  m_file_contents = other.m_file_contents;
54  }
55  return *this;
56 }
57 
59 {
60  return new FileExploration(*this);
61 }
62 
63 std::vector<std::string> FileExploration::GetParameters() const
64 {
65  return {"file"};
66 }
67 
68 std::vector<std::string> FileExploration::GetValues(unsigned int index) const
69 {
70  assert(index < GetNumberOfTasks() && "The given index doesn't exist.");
71 
72  return { m_file_names[index] };
73 }
74 
76 {
77  return m_file_names.size();
78 }
79 
80 SimTask* FileExploration::CreateTask(unsigned int index) const
81 {
82  assert(index < GetNumberOfTasks() && "The given index doesn't exist.");
83 
84 
85  return new SimTask(index, m_file_contents[index], GetPreferences(), GetName());
86 }
87 
89 {
90  ptree pt = this->Exploration::ToPtree();
91 
92  auto index_of = [this](const string& elem){
93  return distance(m_file_names.begin(),
94  find(m_file_names.begin(), m_file_names.end(), elem));
95  };
96 
97  for (const string& name : m_file_names) {
98  ptree file_pt;
99  file_pt.put("name", name);
100  file_pt.put_child("contents", m_file_contents[index_of(name)]);
101  pt.add_child("files.file", file_pt);
102  }
103 
104  return pt;
105 }
106 
107 void FileExploration::ReadPtree(const ptree& pt)
108 {
109  assert(pt.find("files") != pt.not_found() && "No files were found in this exploration.");
110 
111  m_file_names.clear();
112  m_file_contents.clear();
113 
114  for (const auto& pair : pt.get_child("files")) {
115  m_file_names.push_back(pair.second.get<std::string>("name"));
116  m_file_contents.push_back(pair.second.get_child("contents"));
117  }
118 }
119 
120 } // namespace
STL namespace.
virtual boost::property_tree::ptree ToPtree() const
Convert the exploration to a ptree.
virtual FileExploration * Clone() const
Clone function.
Class describing a file-based exploration and its simulation tasks.
virtual std::vector< std::string > GetParameters() const
Returns all the parameters in the exploration.
virtual boost::property_tree::ptree ToPtree() const
Convert the exploration to a ptree.
Definition: Exploration.cpp:51
FileExploration & operator=(const FileExploration &other)
Assignment operator.
virtual std::vector< std::string > GetValues(unsigned int index) const
Return the values of a certain task.
const std::string & GetName() const
Returns the name of the exploration.
Definition: Exploration.h:79
virtual unsigned int GetNumberOfTasks() const
Returns the number of tasks the exploration currently contains.
FileExploration(const std::string &name, const std::vector< std::pair< std::string, boost::property_tree::ptree >> &files, const boost::property_tree::ptree &preferences)
Constructor.
const boost::property_tree::ptree & GetPreferences() const
Returns the preferences of the exploration.
Definition: Exploration.h:84
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
Contains all information needed for a transmitable simulation task.
Definition: SimTask.h:31
Class describing a generic exploration.
Definition: Exploration.h:33
virtual SimTask * CreateTask(unsigned int index) const
Creates a task with the parameters on the given index.
Interface for FileExploration.