1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // Modified by garonne@lal.in2p3.fr |
---|
5 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
6 | //----------------------------------------------------------- |
---|
7 | |
---|
8 | #ifndef __cmt_project_h__ |
---|
9 | #define __cmt_project_h__ |
---|
10 | |
---|
11 | #include "cmt_parser.h" |
---|
12 | #include "cmt_system.h" |
---|
13 | #include "cmt_use.h" |
---|
14 | #include "cmt_awk.h" |
---|
15 | |
---|
16 | class Project; |
---|
17 | |
---|
18 | class StrategyDef |
---|
19 | { |
---|
20 | public: |
---|
21 | typedef cmt_vector <StrategyDef*> StrategyDefs; |
---|
22 | |
---|
23 | cmt_string m_keyword; |
---|
24 | cmt_string m_name; |
---|
25 | cmt_string m_on_value; |
---|
26 | cmt_string m_off_value; |
---|
27 | bool m_default_value; |
---|
28 | bool m_priority_value; |
---|
29 | |
---|
30 | const cmt_string& get_default_value () const; |
---|
31 | }; |
---|
32 | |
---|
33 | class Strategy |
---|
34 | { |
---|
35 | public: |
---|
36 | StrategyDef* m_definition; |
---|
37 | bool m_specified; |
---|
38 | bool m_specified_value; |
---|
39 | bool m_value; |
---|
40 | Tag* m_on_tag; |
---|
41 | Tag* m_off_tag; |
---|
42 | cmt_string m_context; |
---|
43 | |
---|
44 | Strategy (); |
---|
45 | void clear (); |
---|
46 | void set (StrategyDef* definition, bool value, const cmt_string& project_name); |
---|
47 | void update (StrategyDef* definition, bool value, const cmt_string& project_name); |
---|
48 | }; |
---|
49 | |
---|
50 | class StrategyMgr |
---|
51 | { |
---|
52 | public: |
---|
53 | static StrategyMgr& instance (); |
---|
54 | static StrategyDef* find_strategy (const cmt_string& name); |
---|
55 | static bool get_default_strategy (const cmt_string& name); |
---|
56 | static bool get_priority_strategy (const cmt_string& name); |
---|
57 | static StrategyDef::StrategyDefs& get_definitions (); |
---|
58 | |
---|
59 | private: |
---|
60 | StrategyMgr (); |
---|
61 | StrategyDef::StrategyDefs m_defs; |
---|
62 | }; |
---|
63 | |
---|
64 | class ProjectFactory : public IProjectFactory |
---|
65 | { |
---|
66 | public: |
---|
67 | static IProjectFactory& instance (); |
---|
68 | |
---|
69 | public: |
---|
70 | void reset (); |
---|
71 | Project* create_project (const cmt_string& name, |
---|
72 | const cmt_string& path, |
---|
73 | const cmt_string& path_source, |
---|
74 | Project* parent); |
---|
75 | |
---|
76 | }; |
---|
77 | |
---|
78 | class IProjectAction |
---|
79 | { |
---|
80 | public: |
---|
81 | virtual bool run (const Project& project) = 0; |
---|
82 | }; |
---|
83 | |
---|
84 | class IProjectVisitor |
---|
85 | { |
---|
86 | public: |
---|
87 | virtual void pre (Project* p) = 0; |
---|
88 | virtual void in (Project* p) = 0; |
---|
89 | virtual void post (Project* p) = 0; |
---|
90 | }; |
---|
91 | |
---|
92 | class Project |
---|
93 | { |
---|
94 | public: |
---|
95 | |
---|
96 | typedef cmt_vector<Project> ProjectVector; |
---|
97 | typedef cmt_vector<Project*> ProjectPtrVector; |
---|
98 | |
---|
99 | static bool create (const cmt_string& name, |
---|
100 | const cmt_string& release, |
---|
101 | const cmt_string& path); |
---|
102 | |
---|
103 | static Project* find_by_name (const cmt_string& name); |
---|
104 | static Project* find_by_cmtpath (const cmt_string& cmtpath); |
---|
105 | static Project* get_current (); |
---|
106 | static Project* add (const cmt_string& name, |
---|
107 | const cmt_string& release); |
---|
108 | |
---|
109 | static ProjectVector& projects (); |
---|
110 | static void clear_all (); |
---|
111 | static void show_all (); |
---|
112 | static void show_specified_strategies_for_all (); |
---|
113 | static void show_paths (); |
---|
114 | static const cmt_string& get_project_file_name (); |
---|
115 | |
---|
116 | static void fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections); |
---|
117 | |
---|
118 | static void broadcast (IProjectAction& action); |
---|
119 | static void reverse_broadcast (IProjectAction& action); |
---|
120 | static void scan_paths (PathScanner& scanner, PathScanner::actor& actor); |
---|
121 | static void scan_paths_for_package (PathScanner& scanner, const cmt_string& name); |
---|
122 | |
---|
123 | static cmt_string find_in_cmt_paths (const cmt_string& path); |
---|
124 | |
---|
125 | static void fill_cmtpaths (cmt_string& buffer); |
---|
126 | |
---|
127 | static void start_visit (IProjectVisitor& visitor); |
---|
128 | |
---|
129 | public: |
---|
130 | |
---|
131 | Project (); |
---|
132 | |
---|
133 | const cmt_string& get_name () const; |
---|
134 | const cmt_string& get_release () const; |
---|
135 | const cmt_string& get_container () const; |
---|
136 | const cmt_string& get_container_version () const; |
---|
137 | const cmt_string& get_cmtpath () const; |
---|
138 | const cmt_string& get_cmtpath_pwd () const; |
---|
139 | const cmt_string& get_cmtpath_source () const; |
---|
140 | int get_children_size () const; |
---|
141 | |
---|
142 | const CmtSystem::cmt_string_vector get_project_releases(const cmt_string& name) const; |
---|
143 | bool select_release(const cmt_string& name, const cmt_string& release, cmt_string& result); |
---|
144 | |
---|
145 | Project* get_child (int index) const; |
---|
146 | bool visited () const; |
---|
147 | |
---|
148 | void set_name (const cmt_string& name); |
---|
149 | void set_release (const cmt_string& release); |
---|
150 | void set_container (const cmt_string& container); |
---|
151 | void set_container_version (const cmt_string& version); |
---|
152 | void set_cmtpath (const cmt_string& path); |
---|
153 | void set_cmtpath_pwd (const cmt_string& path); |
---|
154 | void set_cmtpath_source (const cmt_string& source); |
---|
155 | void clear (); |
---|
156 | void configure (); |
---|
157 | bool has_parents () const; |
---|
158 | bool has_parent (Project* p) const; |
---|
159 | bool has_child (Project* p) const; |
---|
160 | void add_parent (Project* p); |
---|
161 | void add_child (Project* p); |
---|
162 | |
---|
163 | void container_action (const cmt_string& name, const cmt_string& version); |
---|
164 | void use_action (const cmt_string& name, const cmt_string& release); |
---|
165 | |
---|
166 | Project& operator = (const Project& other); |
---|
167 | bool operator == (const cmt_string& name) const; |
---|
168 | bool operator != (const cmt_string& name) const; |
---|
169 | |
---|
170 | void show (); |
---|
171 | void show_specified_strategies () const; |
---|
172 | |
---|
173 | bool has_strategy (const StrategyDef* definition) const; |
---|
174 | bool is_specified (const StrategyDef* definition) const; |
---|
175 | bool get_strategy (const StrategyDef* definition) const; |
---|
176 | bool get_strategy (const cmt_string& name) const; |
---|
177 | void set_default_strategy (const cmt_string& name); |
---|
178 | void set_strategy (const cmt_string& name, const cmt_string& value, const cmt_string& context); |
---|
179 | void set_strategy (StrategyDef* definition, bool b_value, const cmt_string& context); |
---|
180 | void update_strategy (StrategyDef* definition, bool b_value); |
---|
181 | void update_strategy_from_children (StrategyDef* definition); |
---|
182 | void update_strategies_from_children (); |
---|
183 | void set_author (const cmt_string& name); |
---|
184 | const cmt_string& get_author () const; |
---|
185 | void project_author_action (const CmtSystem::cmt_string_vector& words); |
---|
186 | // bool get_author (const cmt_string& name) const; |
---|
187 | |
---|
188 | void visit (IProjectVisitor& visitor); |
---|
189 | |
---|
190 | // Use |
---|
191 | Use* get_use () const; |
---|
192 | void set_use (Use* use); |
---|
193 | |
---|
194 | private: |
---|
195 | |
---|
196 | void fill_cmtpath (cmt_string& buffer); |
---|
197 | |
---|
198 | cmt_string m_name; |
---|
199 | cmt_string m_author; |
---|
200 | cmt_string m_release; |
---|
201 | cmt_string m_container; |
---|
202 | cmt_string m_container_version; |
---|
203 | |
---|
204 | ProjectPtrVector m_parents; |
---|
205 | ProjectPtrVector m_children; |
---|
206 | |
---|
207 | bool m_visited; |
---|
208 | |
---|
209 | cmt_string m_cmtpath; |
---|
210 | cmt_string m_cmtpath_pwd; |
---|
211 | cmt_string m_cmtpath_source; |
---|
212 | |
---|
213 | bool m_configured; |
---|
214 | |
---|
215 | cmt_vector <Strategy> m_strategies; |
---|
216 | |
---|
217 | Use* m_use; |
---|
218 | }; |
---|
219 | |
---|
220 | |
---|
221 | #endif |
---|