# 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_V_SUPPORT(CRL::SearchPath::Element);
116
117
118 #endif // CRL_SEARCH_PATH_H
CRL::SearchPath::getSelected
const std::string & getSelected() const
Definition: SearchPath.h:90
CRL::SearchPath::reset
void reset()
Definition: SearchPath.h:88
CRL::SearchPath::extractLibName
static std::string extractLibName(const std::string &)
CRL::SearchPath::getIndex
size_t getIndex() const
Definition: SearchPath.h:91
CRL::SearchPath::hasSelected
bool hasSelected() const
Definition: SearchPath.h:92
CRL::SearchPath::locate
size_t locate(const std::string &file, std::ios::openmode mode=std::ios::in, int first=0, int last=64)
CRL::SearchPath::Element
An element of the search path (mapping a directory).
Definition: SearchPath.h:34
CRL::SearchPath::getSize
size_t getSize() const
Definition: SearchPath.h:89
CRL::SearchPath::hasPath
size_t hasPath(const std::string &path) const
CRL::SearchPath
An ordered list of search pathes.
Definition: SearchPath.h:32
CRL::SearchPath::prepend
size_t prepend(const std::string &path, const std::string &name="")
CRL::SearchPath::Element::empty
bool empty() const
Definition: SearchPath.h:105
CRL::SearchPath::Element::getPath
const std::string & getPath() const
Definition: SearchPath.h:106
CRL::SearchPath::Element::getName
const std::string & getName() const
Definition: SearchPath.h:107
CRL
The namespace of Coriolis Core.
Definition: Environment.h:26
CRL::SearchPath::replace
size_t replace(const std::string &path, const std::string &, size_t index)
CRL::SearchPath::Element::Element
Element(const std::string &path="", const std::string &name="")
Definition: SearchPath.h:100
CRL::SearchPath::append
size_t append(const std::string &path, const std::string &name="")
Definition: SearchPath.h:95
CRL::SearchPath::operator[]
const Element & operator[](size_t index) const

Generated by doxygen 1.8.14 on Mon Apr 27 2020 | Return to top of page

Coriolis Core (CRL) | Copyright © 2008-2016 UPMC All rights reserved