VPTissue Reference Manual
StartupFileBase.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  */
21 #include "StartupFileHdf5.h"
22 #include "StartupFileXml.h"
23 #include "StartupFileXmlGz.h"
24 
25 #include <algorithm>
26 #include <string>
27 
28 namespace SimPT_Shell {
29 namespace Ws {
30 
31 using namespace std;
32 using namespace SimPT_Sim::Util;
33 
35  : m_path(path)
36 {
37 }
38 
39 const string& StartupFileBase::GetPath() const
40 {
41  return m_path;
42 }
43 
44 const StartupFileBase::ConstructorType StartupFileBase::Constructor(
45  [](const string& filename, const string& path) -> shared_ptr<IFile>
46  {
47  auto endswith = [](const string& s1, const string& s2) {
48  if (s2.length() > s1.length()) {
49  return false;
50  }
51  std::string s1lower = s1;
52  std::transform(s1lower.begin(), s1lower.end(), s1lower.begin(), ::tolower);
53  std::string s2lower = s2;
54  std::transform(s2lower.begin(), s2lower.end(), s2lower.begin(), ::tolower);
55 
56  return s1lower.compare(s1lower.length()-s2lower.length(), string::npos, s2lower) == 0;
57  };
58 
59  if (endswith(filename, ".h5")) {
60  return make_shared<StartupFileHdf5>(path);
61  } else if (endswith(filename, ".xml")) {
62  return make_shared<StartupFileXml>(path);
63  } else if (endswith(filename, ".xml.gz")) {
64  return make_shared<StartupFileXmlGz>(path);
65  }
66  return nullptr;
67  }
68 );
69 
70 
71 } // namespace
72 } // namespace
Interface for Hdf5 tissue file format.
STL namespace.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Namespace for SimPT shell package.
Definition: Client.cpp:50
StartupFileBase(const std::string &path)
Constructor.
Interface for StartupFileXml.
std::function< std::shared_ptr< IFile >(const std::string &, const std::string &)> ConstructorType
First argument: filename.
Definition: IFile.h:47
virtual const std::string & GetPath() const
Interface for StartupFileXmlGz.