pid
pid_path.h
Go to the documentation of this file.
1 /* File: pid_path.h
2  * This file is part of the program pid-rpath
3  * Program description : Default package of PID, used to manage runtime
4  * path of executables
5  * Copyright (C) 2015 - Robin Passama (LIRMM). All Right reserved.
6  *
7  * This software is free software: you can redistribute it and/or modify
8  * it under the terms of the CeCILL-C license as published by
9  * the CEA CNRS INRIA, either version 1
10  * of the License, or (at your option) any later version.
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * CeCILL-C License for more details.
15  *
16  * You should have received a copy of the CeCILL-C License
17  * along with this software. If not, it can be found on the official
18  * website
19  * of the CeCILL licenses family (http://www.cecill.info/index.en.html).
20  */
21 
31 #pragma once
32 
33 #include <set>
34 #include <string>
38 namespace pid {
39 
43 class PidVersion {
44 private:
45  unsigned int major_, minor_, patch_;
46 
47 public:
48  PidVersion();
49  PidVersion(const PidVersion& version);
50  PidVersion(const std::string& version);
52  PidVersion& operator=(const std::string&);
53  bool operator<(const PidVersion& other) const;
54  bool operator>(const PidVersion& other) const;
55  bool operator==(const PidVersion& other) const;
56  bool operator!=(const PidVersion& other) const;
57  bool operator<=(const PidVersion& other) const;
58  bool operator>=(const PidVersion& other) const;
59  friend std::ostream& operator<<(std::ostream& stream,
60  const PidVersion& ver);
61 
67  bool from_String(const std::string& value);
68 
73  std::string to_String() const;
74 };
75 
82 private:
83  typedef enum {
86  IN_RANGE_VERSION, // max version is used
88  OLDER_EQUAL_THAN_VERSION, // max version is used
91 
92  VersionConstraintType constraint_; // if exact only min is considered
95 
96 public:
99  PidVersionConstraint(const std::string& expression);
101  PidVersionConstraint& operator=(const std::string& expression);
102  bool operator!=(const PidVersionConstraint&) const;
103  bool operator==(const PidVersionConstraint&) const;
104  friend std::ostream& operator<<(std::ostream& stream,
105  const PidVersionConstraint& ver);
106 
111  const PidVersion& min() const;
112 
117  const PidVersion& exact() const;
118 
123  const PidVersion& max() const;
124 
133  PidVersion
134  select(const std::set< PidVersion >& all_possible_versions) const;
135 
144  bool from_String(const std::string& value);
145 
151  std::string to_String() const;
152 
157  bool undefined() const;
158 };
159 
166 class PidPath {
167 
168 public:
169  PidPath();
170  PidPath(const PidPath&);
171  virtual ~PidPath();
172  bool operator==(const PidPath& compared) const;
173  PidPath& operator=(const PidPath& copied);
174 
184  explicit PidPath(const std::string& str);
185 
196  PidPath& operator=(const std::string& str);
197 
209  bool from_String(const std::string& value);
210 
216  std::string to_String() const;
217 
218  void set_Dynamic_Path(const std::string& package,
219  const std::string& version, const std::string& path,
220  bool write_new_file);
221  void set_Static_Path(const std::string& path, bool write_new_file);
222  void set_Dynamic_Component(const std::string& package,
223  const std::string& version,
224  const std::string& component,
225  bool is_executable);
226  void set_Static_Component(const std::string& package,
227  const std::string& component, bool is_executable);
228 
238  std::string resolve();
239 
244  bool is_Absolute() const;
249  bool is_Package_Relative() const;
250 
255  void write_Target();
256 
261  bool is_Target_Component() const;
262 
267  bool is_Target_Executable_Component() const;
268 
273  bool is_Target_Module_Component() const;
274 
280  bool is_Target_Written() const;
281 
286  const std::string& get_Path_Expression() const;
294  const std::string& get_Package() const;
295 
301  const PidVersionConstraint& get_Version() const;
302 
303 private:
304  std::string package_;
306  std::string path_;
309  unsigned char is_component_;
310 
312 };
313 } // namespace pid
pid::PidPath::RuntimeComponentType
RuntimeComponentType
Definition: pid_path.h:311
pid::PidPath::is_absolute_
bool is_absolute_
Definition: pid_path.h:308
pid::PidPath::is_Target_Module_Component
bool is_Target_Module_Component() const
tell whether the target is a module component.
pid::PidVersionConstraint::max
const PidVersion & max() const
get the max version required, if any.
pid::PidPath::path_
std::string path_
Definition: pid_path.h:306
pid::PidPath::from_String
bool from_String(const std::string &value)
fill the PidPath object with info comming from a string.
pid::PidVersionConstraint::select
PidVersion select(const std::set< PidVersion > &all_possible_versions) const
select the best version as regard of constraints considering all versions.
pid::PidVersionConstraint::operator<<
friend std::ostream & operator<<(std::ostream &stream, const PidVersionConstraint &ver)
pid::PidVersionConstraint::operator=
PidVersionConstraint & operator=(const PidVersionConstraint &)
pid::PidPath::operator==
bool operator==(const PidPath &compared) const
pid::PidVersion::patch_
unsigned int patch_
Definition: pid_path.h:45
pid
root namespace for pid packages.
Definition: bitmask.h:51
pid::PidPath::write_new_file_
bool write_new_file_
Definition: pid_path.h:307
pid::PidPath::operator=
PidPath & operator=(const PidPath &copied)
pid::PidVersionConstraint::NEWER_EQUAL_THAN_VERSION
@ NEWER_EQUAL_THAN_VERSION
Definition: pid_path.h:89
pid::PidPath::version_
PidVersionConstraint version_
Definition: pid_path.h:305
pid::PidPath
defines a runtime path to a resource.
Definition: pid_path.h:166
pid::PidVersionConstraint::exact
const PidVersion & exact() const
get the exact version required, if any.
pid::PidVersion::operator<<
friend std::ostream & operator<<(std::ostream &stream, const PidVersion &ver)
pid::PidPath::PidPath
PidPath()
pid::PidPath::set_Static_Path
void set_Static_Path(const std::string &path, bool write_new_file)
pid::PidVersionConstraint::VersionConstraintType
VersionConstraintType
Definition: pid_path.h:83
pid::PidVersion::major_
unsigned int major_
Definition: pid_path.h:45
pid::PidVersionConstraint::EXACT_VERSION
@ EXACT_VERSION
Definition: pid_path.h:85
pid::PidPath::is_Target_Component
bool is_Target_Component() const
tell whether the target is a runtime component.
pid::PidVersionConstraint::undefined
bool undefined() const
tell whether a constraint is specified or not
pid::PidPath::set_Dynamic_Component
void set_Dynamic_Component(const std::string &package, const std::string &version, const std::string &component, bool is_executable)
pid::PidVersion::minor_
unsigned int minor_
Definition: pid_path.h:45
pid::PidVersionConstraint::max_version_
PidVersion max_version_
Definition: pid_path.h:94
pid::PidVersion::operator!=
bool operator!=(const PidVersion &other) const
pid::PidVersion::operator<=
bool operator<=(const PidVersion &other) const
pid::PidVersionConstraint::constraint_
VersionConstraintType constraint_
Definition: pid_path.h:92
pid::PidVersionConstraint::operator!=
bool operator!=(const PidVersionConstraint &) const
pid::PidPath::set_Static_Component
void set_Static_Component(const std::string &package, const std::string &component, bool is_executable)
pid::PidVersion
class for representing version (in PID system) at runtime..
Definition: pid_path.h:43
pid::PidVersionConstraint::to_String
std::string to_String() const
output the version constraint object as a string
pid::PidVersion::operator<
bool operator<(const PidVersion &other) const
pid::PidVersion::operator>=
bool operator>=(const PidVersion &other) const
pid::PidPath::get_Version
const PidVersionConstraint & get_Version() const
raw access to the version constraint object, if any.
pid::PidPath::is_Package_Relative
bool is_Package_Relative() const
tell whether the target path is relative to a specific package.
pid::PidVersionConstraint::OLDER_EQUAL_THAN_VERSION
@ OLDER_EQUAL_THAN_VERSION
Definition: pid_path.h:88
pid::PidPath::is_Target_Written
bool is_Target_Written() const
tell whether the target path may be written by the current executable.
pid::PidVersionConstraint::min_or_exact_version_
PidVersion min_or_exact_version_
Definition: pid_path.h:93
pid::PidPath::package_
std::string package_
Definition: pid_path.h:304
pid::PidPath::resolve
std::string resolve()
resolve the current object as a canonical path string.
pid::PidPath::~PidPath
virtual ~PidPath()
pid::PidVersionConstraint::min
const PidVersion & min() const
get the min version required, if any.
pid::PidPath::is_Absolute
bool is_Absolute() const
tell whether the target path is absolute or relative.
pid::PidVersion::PidVersion
PidVersion()
pid::PidVersionConstraint::IN_RANGE_VERSION
@ IN_RANGE_VERSION
Definition: pid_path.h:86
pid::PidVersion::operator>
bool operator>(const PidVersion &other) const
pid::PidPath::to_String
std::string to_String() const
output the pid path object as a string.
pid::PidVersion::operator=
PidVersion & operator=(const PidVersion &)
pid::PidVersionConstraint::from_String
bool from_String(const std::string &value)
fill the version constraint object with info comming from a string.
pid::PidVersion::from_String
bool from_String(const std::string &value)
fill the version object with info comming from a string.
pid::PidPath::IS_NOT_COMPONENT
@ IS_NOT_COMPONENT
Definition: pid_path.h:311
pid::PidPath::write_Target
void write_Target()
sets the path so that it may write target file.
pid::PidVersionConstraint::operator==
bool operator==(const PidVersionConstraint &) const
pid::PidPath::get_Package
const std::string & get_Package() const
raw access to the target package.
pid::PidVersion::to_String
std::string to_String() const
output the version object as a string
pid::PidVersion::operator==
bool operator==(const PidVersion &other) const
pid::PidPath::set_Dynamic_Path
void set_Dynamic_Path(const std::string &package, const std::string &version, const std::string &path, bool write_new_file)
pid::PidPath::IS_EXE
@ IS_EXE
Definition: pid_path.h:311
pid::PidPath::IS_MODULE
@ IS_MODULE
Definition: pid_path.h:311
pid::PidVersionConstraint
class for representing constraints on target version (in PID system) at runtime.
Definition: pid_path.h:81
pid::PidVersionConstraint::PidVersionConstraint
PidVersionConstraint()
pid::PidVersionConstraint::ANY_VERSION
@ ANY_VERSION
Definition: pid_path.h:87
pid::PidPath::get_Path_Expression
const std::string & get_Path_Expression() const
raw access to the path expression.
pid::PidPath::is_Target_Executable_Component
bool is_Target_Executable_Component() const
tell whether the target is an executable component.
pid::PidVersionConstraint::NO_CONSTRAINT
@ NO_CONSTRAINT
Definition: pid_path.h:84
pid::PidPath::is_component_
unsigned char is_component_
Definition: pid_path.h:309