1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
5 | //----------------------------------------------------------- |
---|
6 | |
---|
7 | #ifndef __cmt_use_h__ |
---|
8 | #define __cmt_use_h__ |
---|
9 | |
---|
10 | #include "cmt_map.h" |
---|
11 | #include "cmt_include.h" |
---|
12 | #include "cmt_script.h" |
---|
13 | #include "cmt_pattern.h" |
---|
14 | #include "cmt_scope_section.h" |
---|
15 | |
---|
16 | class Package; |
---|
17 | class UseProjectAction; |
---|
18 | |
---|
19 | class Use |
---|
20 | { |
---|
21 | // Public class methods |
---|
22 | public: |
---|
23 | typedef cmt_vector<Use> UseVector; |
---|
24 | typedef cmt_vector<Use*> UsePtrVector; |
---|
25 | |
---|
26 | static Use* action (const CmtSystem::cmt_string_vector& words, Use* use); |
---|
27 | static Use* find (const cmt_string& package, |
---|
28 | const cmt_string& version = "", |
---|
29 | const cmt_string& path = ""); |
---|
30 | static int find_index (const cmt_string& package, |
---|
31 | const cmt_string& version, |
---|
32 | const cmt_string& path); |
---|
33 | static void set_auto_imports_state (int use_index, |
---|
34 | cmt_vector<bool>& auto_imports_states); |
---|
35 | static Use* add (const cmt_string& path, |
---|
36 | const cmt_string& package, |
---|
37 | const cmt_string& version, |
---|
38 | const cmt_string& version_alias, |
---|
39 | const cmt_string& path_alias, |
---|
40 | Use* context_use, |
---|
41 | State specified_auto_imports = Unspecified); |
---|
42 | static void move (Use* use1); |
---|
43 | static void reorder (Use* use1, Use* use2); |
---|
44 | static void select_clients (const cmt_string& package, |
---|
45 | const cmt_string& version); |
---|
46 | static void show_all (bool skip_discarded = false); |
---|
47 | static void show_all (const cmt_string& prefix, bool skip_discarded = false); |
---|
48 | |
---|
49 | static Use& current (); |
---|
50 | static const Use& const_current (); |
---|
51 | |
---|
52 | static UseVector& get_instances (); |
---|
53 | static UsePtrVector& get_ordered_uses (); |
---|
54 | |
---|
55 | static void clear_all (); |
---|
56 | static void unselect_all (); |
---|
57 | static void undiscard_all (); |
---|
58 | static void fill_macro_all (cmt_string& buffer, const cmt_string& suffix); |
---|
59 | |
---|
60 | // Private class methods |
---|
61 | private: |
---|
62 | static Use* create (const cmt_string& path, |
---|
63 | const cmt_string& package, |
---|
64 | const cmt_string& version, |
---|
65 | const cmt_string& version_alias, |
---|
66 | const cmt_string& path_alias); |
---|
67 | |
---|
68 | // Public instance methods |
---|
69 | public: |
---|
70 | Use (); |
---|
71 | Use (const cmt_string& new_package, |
---|
72 | const cmt_string& new_version, |
---|
73 | const cmt_string& new_path); |
---|
74 | ~Use (); |
---|
75 | void set (const cmt_string& new_package, |
---|
76 | const cmt_string& new_version, |
---|
77 | const cmt_string& new_path, |
---|
78 | const cmt_string& new_version_alias = "", |
---|
79 | const cmt_string& new_path_alias = ""); |
---|
80 | void author_action (const CmtSystem::cmt_string_vector& words); |
---|
81 | void manager_action (const CmtSystem::cmt_string_vector& words); |
---|
82 | bool move_to (); |
---|
83 | void discard (); |
---|
84 | void undiscard (); |
---|
85 | void apply_global_patterns (); |
---|
86 | void set_include_path (const cmt_string& new_path); |
---|
87 | void get_full_path (cmt_string& s) const; |
---|
88 | cmt_string get_full_path () const; |
---|
89 | void reduce_path (cmt_string& s) const; |
---|
90 | void get_cmtpath_and_offset (cmt_string& cmtpath, cmt_string& offset) const; |
---|
91 | bool get_strategy (const cmt_string& name) const; |
---|
92 | |
---|
93 | void fill_includes_macro (cmt_string& buffer) const; |
---|
94 | void fill_macro (cmt_string& buffer, const cmt_string& suffix) const; |
---|
95 | void fill_standard_macros (cmt_string& buffer) const; |
---|
96 | void build_library_links (const cmt_string& cmtinstallarea, |
---|
97 | const cmt_string& tag, |
---|
98 | const cmt_string& shlibsuffix, |
---|
99 | const cmt_string& symlinkcmd) const; |
---|
100 | |
---|
101 | bool get_all_clients (const cmt_string& to_name); |
---|
102 | |
---|
103 | bool get_paths (Use* to, UsePtrVector& list); |
---|
104 | |
---|
105 | bool located () const; |
---|
106 | |
---|
107 | void change_path (const cmt_string& path); |
---|
108 | void set_auto_imports (State new_state); |
---|
109 | void set_native_version (bool state); |
---|
110 | bool has_native_version () const; |
---|
111 | |
---|
112 | Package* get_package () const; |
---|
113 | const cmt_string& get_package_name () const; |
---|
114 | void set_package_name (const cmt_string& name); |
---|
115 | |
---|
116 | int get_index () const; |
---|
117 | |
---|
118 | void show_cycles (); |
---|
119 | |
---|
120 | void push_scope_section (ScopeType type); |
---|
121 | void pop_scope_section (); |
---|
122 | void close_scope_sections (); |
---|
123 | |
---|
124 | ScopeType get_current_scope () const; |
---|
125 | |
---|
126 | // Public attributes |
---|
127 | public: |
---|
128 | |
---|
129 | cmt_string specified_version; /* idem */ |
---|
130 | cmt_string specified_path; /* idem */ |
---|
131 | cmt_string version_alias; |
---|
132 | cmt_string path_alias; |
---|
133 | cmt_string author; /* idem */ |
---|
134 | cmt_string manager; /* idem */ |
---|
135 | |
---|
136 | cmt_string path; /* expanded path */ |
---|
137 | cmt_string version; /* idem */ |
---|
138 | cmt_string real_path; |
---|
139 | CmtDirStyle style; /* May be cmt or mgr */ |
---|
140 | |
---|
141 | cmt_string prefix; /* upper case copy of package */ |
---|
142 | bool done; /* true when requirements file has |
---|
143 | already been read */ |
---|
144 | bool discarded; /* discarded by version strategy */ |
---|
145 | bool selected; /* used for recursive access */ |
---|
146 | |
---|
147 | State auto_imports; |
---|
148 | |
---|
149 | Include::IncludeVector includes; |
---|
150 | cmt_string include_path; |
---|
151 | Script::ScriptVector scripts; |
---|
152 | ApplyPattern::ApplyPatternVector apply_patterns; |
---|
153 | IgnorePattern::IgnorePatternVector ignore_patterns; |
---|
154 | |
---|
155 | // Private methods |
---|
156 | private: |
---|
157 | void clear (); |
---|
158 | int reach_package (const cmt_string& current_path); |
---|
159 | void select (); |
---|
160 | void unselect (); |
---|
161 | bool is_selected (); |
---|
162 | bool is_client (const cmt_string& package, |
---|
163 | const cmt_string& version); |
---|
164 | void show_sub_uses (const cmt_string& request, bool skip_discarded = false); |
---|
165 | bool select_alternate (); |
---|
166 | Use* get_selected_version (); |
---|
167 | Use* set_selected_version (Use* selected_use); |
---|
168 | |
---|
169 | static bool need_new (const cmt_string& path, |
---|
170 | const cmt_string& package, |
---|
171 | const cmt_string& version, |
---|
172 | Use** old_use, |
---|
173 | Use* context_use); |
---|
174 | |
---|
175 | bool get_all_clients (Use* to, |
---|
176 | const cmt_string& result, |
---|
177 | cmt_map <cmt_string, Use*>& all_clients, |
---|
178 | cmt_map <cmt_string, Use*>& all_clients_ok); |
---|
179 | |
---|
180 | // Private attributes |
---|
181 | private: |
---|
182 | |
---|
183 | Package* m_package; |
---|
184 | //cmt_string m_package_name; /* directly read from requirements */ |
---|
185 | |
---|
186 | bool m_located; |
---|
187 | bool m_has_native_version; |
---|
188 | |
---|
189 | UsePtrVector sub_uses; |
---|
190 | cmt_vector<ScopeType> sub_use_scopes; |
---|
191 | cmt_vector<State> sub_use_auto_imports; |
---|
192 | |
---|
193 | ScopeType initial_scope; |
---|
194 | cmt_vector<ScopeSection> scope_sections; |
---|
195 | |
---|
196 | CmtSystem::cmt_string_vector alternate_versions; |
---|
197 | CmtSystem::cmt_string_vector alternate_paths; |
---|
198 | |
---|
199 | CmtSystem::cmt_string_vector requests; |
---|
200 | |
---|
201 | int m_index; // Position within the ordered list of uses |
---|
202 | |
---|
203 | friend class UseProjectAction; |
---|
204 | }; |
---|
205 | |
---|
206 | class Package |
---|
207 | { |
---|
208 | public: |
---|
209 | |
---|
210 | typedef cmt_map<cmt_string, Package> PackageMap; |
---|
211 | typedef cmt_vector<Package> PackageVector; |
---|
212 | |
---|
213 | static Package* find (const cmt_string& name); |
---|
214 | static Package* add (const cmt_string& name); |
---|
215 | |
---|
216 | static PackageVector& packages (); |
---|
217 | static PackageMap& package_map (); |
---|
218 | |
---|
219 | static void clear_all (); |
---|
220 | |
---|
221 | public: |
---|
222 | |
---|
223 | Package (); |
---|
224 | ~Package (); |
---|
225 | |
---|
226 | const cmt_string& get_name () const; |
---|
227 | void add_use (Use* use); |
---|
228 | void remove_use (Use* use); |
---|
229 | Use::UsePtrVector& get_uses (); |
---|
230 | |
---|
231 | bool is_cmt (); |
---|
232 | |
---|
233 | private: |
---|
234 | bool m_is_cmt; |
---|
235 | |
---|
236 | cmt_string m_name; |
---|
237 | Use::UsePtrVector m_uses; |
---|
238 | }; |
---|
239 | |
---|
240 | #endif |
---|