Coriolis Core (CRL) Documentation


SearchPath.h
1 // -*- C++ -*-
2 //
3 // This file is part of the Coriolis Software.
4 // Copyright (c) UPMC 2008-2018, All Rights Reserved
5 //
6 // +-----------------------------------------------------------------+
7 // | C O R I O L I S |
8 // | Alliance / Hurricane Interface |
9 // | |
10 // | Author : Jean-Paul CHAPUT |
11 // | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
12 // | =============================================================== |
13 // | C++ Header : "./crlcore/SearchPath.h" |
14 // +-----------------------------------------------------------------+
15 
16 
17 #ifndef CRL_SEARCH_PATH_H
18 #define CRL_SEARCH_PATH_H
19 
20 #include <string>
21 #include <vector>
22 #include "hurricane/Commons.h"
23 #include "hurricane/Slot.h"
24 
25 
26 namespace CRL {
27 
28  using Hurricane::Record;
29  using Hurricane::_TName;
30 
31 
32  class SearchPath {
33  public:
34  class Element {
35  public:
36  inline Element ( const std::string& path="", const std::string& name="" );
37  inline bool empty () const;
38  inline const std::string& getPath () const;
39  inline const std::string& getName () const;
40  inline std::string _getTypeName () const;
41  std::string _getString () const;
42  Record* _getRecord () const;
43  private:
44  std::string _path;
45  std::string _name;
46  };
47  public:
48  static const size_t npos;
49  static std::string extractLibName ( const std::string& );
50  SearchPath ();
51  public:
52  inline void reset ();
53  inline size_t append ( const std::string& path, const std::string& name="" );
54  size_t prepend ( const std::string& path, const std::string& name="");
55  size_t replace ( const std::string& path, const std::string&, size_t index );
56  void remove ( size_t index );
57  size_t locate ( const std::string& file
58  , std::ios::openmode mode =std::ios::in
59  , int first=0
60  , int last =64 );
61  void select ( const std::string& );
62  inline size_t getSize () const;
63  inline const std::string& getSelected () const;
64  inline size_t getIndex () const;
65  inline bool hasSelected () const;
66  size_t hasLib ( const std::string& name ) const;
67  size_t hasPath ( const std::string& path ) const;
68  const Element& operator[] ( size_t index ) const;
69  private:
70  static const std::string _selectFailed;
71  std::vector<Element> _paths;
72  size_t _index;
73  std::string _selected;
74  private:
75  SearchPath ( const SearchPath& );
76  bool _canOpen ( const Element& directory
77  , const std::string& file
78  , std::ios::openmode mode
79  );
80  public:
81  inline std::string _getTypeName () const;
82  std::string _getString () const;
83  Record* _getRecord () const;
84  };
85 
86 
87  // Inline Functions.
88  inline void SearchPath::reset () { _paths.resize(1); }
89  inline size_t SearchPath::getSize () const { return _paths.size(); }
90  inline const std::string& SearchPath::getSelected () const { return _selected; }
91  inline size_t SearchPath::getIndex () const { return _index; }
92  inline bool SearchPath::hasSelected () const { return _index != npos; }
93  inline std::string SearchPath::_getTypeName () const { return _TName("SearchPath"); }
94 
95  inline size_t SearchPath::append ( const std::string& path, const std::string& name ) {
96  _paths.push_back ( Element ( path, name.empty()?extractLibName(path):name ) );
97  return _paths.size()-1;
98  }
99 
100  inline SearchPath::Element::Element ( const std::string& path, const std::string& name )
101  : _path(path)
102  , _name(name.empty()?SearchPath::extractLibName(path):name)
103  { }
104 
105  inline bool SearchPath::Element::empty () const { return _path.empty() and _name.empty(); }
106  inline const std::string& SearchPath::Element::getPath () const { return _path; }
107  inline const std::string& SearchPath::Element::getName () const { return _name; }
108  inline std::string SearchPath::Element::_getTypeName () const { return "SearchPath::Element"; }
109 
110 
111 } // CRL namespace.
112 
113 
114 INSPECTOR_P_SUPPORT(CRL::SearchPath);
115 INSPECTOR_PR_SUPPORT(CRL::SearchPath::Element);
116 
117 
118 #endif // CRL_SEARCH_PATH_H
const std::string & getSelected() const
Definition: SearchPath.h:90
void reset()
Definition: SearchPath.h:88
static std::string extractLibName(const std::string &)
size_t getIndex() const
Definition: SearchPath.h:91
bool hasSelected() const
Definition: SearchPath.h:92
size_t locate(const std::string &file, std::ios::openmode mode=std::ios::in, int first=0, int last=64)
An element of the search path (mapping a directory).
Definition: SearchPath.h:34
size_t getSize() const
Definition: SearchPath.h:89
size_t hasPath(const std::string &path) const
An ordered list of search pathes.
Definition: SearchPath.h:32
size_t prepend(const std::string &path, const std::string &name="")
bool empty() const
Definition: SearchPath.h:105
const std::string & getPath() const
Definition: SearchPath.h:106
const std::string & getName() const
Definition: SearchPath.h:107
The namespace of Coriolis Core.
Definition: Environment.h:24
size_t replace(const std::string &path, const std::string &, size_t index)
Element(const std::string &path="", const std::string &name="")
Definition: SearchPath.h:100
size_t append(const std::string &path, const std::string &name="")
Definition: SearchPath.h:95
const Element & operator[](size_t index) const


Generated by doxygen 1.8.14 on Sun Nov 21 2021 Return to top of page
Coriolis Core (CRL) Copyright © 2008-2020 Sorbonne Universite, All rights reserved