[2] | 1 | //----------------------------------------------------------- |
---|
| 2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
| 3 | // arnault@lal.in2p3.fr |
---|
[272] | 4 | // Modified by garonne@lal.in2p3.fr |
---|
[2] | 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" |
---|
[295] | 13 | #include "cmt_use.h" |
---|
[2] | 14 | #include "cmt_awk.h" |
---|
| 15 | |
---|
| 16 | class Project; |
---|
| 17 | |
---|
[15] | 18 | class StrategyDef |
---|
| 19 | { |
---|
| 20 | public: |
---|
| 21 | typedef cmt_vector <StrategyDef*> StrategyDefs; |
---|
| 22 | |
---|
[16] | 23 | cmt_string m_keyword; |
---|
[15] | 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; |
---|
[16] | 42 | cmt_string m_context; |
---|
[15] | 43 | |
---|
[16] | 44 | Strategy (); |
---|
| 45 | void clear (); |
---|
[15] | 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 | |
---|
[2] | 64 | class ProjectFactory : public IProjectFactory |
---|
| 65 | { |
---|
| 66 | public: |
---|
| 67 | static IProjectFactory& instance (); |
---|
| 68 | |
---|
| 69 | public: |
---|
| 70 | void reset (); |
---|
[18] | 71 | Project* create_project (const cmt_string& name, |
---|
| 72 | const cmt_string& path, |
---|
[9] | 73 | const cmt_string& path_source, |
---|
| 74 | Project* parent); |
---|
[2] | 75 | |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | class IProjectAction |
---|
| 79 | { |
---|
| 80 | public: |
---|
| 81 | virtual bool run (const Project& project) = 0; |
---|
| 82 | }; |
---|
| 83 | |
---|
[9] | 84 | class IProjectVisitor |
---|
| 85 | { |
---|
| 86 | public: |
---|
| 87 | virtual void pre (Project* p) = 0; |
---|
| 88 | virtual void in (Project* p) = 0; |
---|
[470] | 89 | virtual void in_again (Project* p) = 0; |
---|
[9] | 90 | virtual void post (Project* p) = 0; |
---|
| 91 | }; |
---|
| 92 | |
---|
[2] | 93 | class Project |
---|
| 94 | { |
---|
| 95 | public: |
---|
| 96 | |
---|
| 97 | typedef cmt_vector<Project> ProjectVector; |
---|
[9] | 98 | typedef cmt_vector<Project*> ProjectPtrVector; |
---|
[652] | 99 | typedef cmt_vector<const Project*> ConstProjectPtrVector; |
---|
[2] | 100 | |
---|
[79] | 101 | static bool create (const cmt_string& name, |
---|
[22] | 102 | const cmt_string& release, |
---|
| 103 | const cmt_string& path); |
---|
[2] | 104 | |
---|
| 105 | static Project* find_by_name (const cmt_string& name); |
---|
| 106 | static Project* find_by_cmtpath (const cmt_string& cmtpath); |
---|
| 107 | static Project* get_current (); |
---|
[8] | 108 | static Project* add (const cmt_string& name, |
---|
| 109 | const cmt_string& release); |
---|
[2] | 110 | |
---|
| 111 | static ProjectVector& projects (); |
---|
[535] | 112 | static ProjectPtrVector& ordered_projects (); |
---|
| 113 | static void order_all (); |
---|
[2] | 114 | static void clear_all (); |
---|
[550] | 115 | static void show_all (PrintMode mode = Csh); // Csh is default for ArgParser::mode |
---|
| 116 | // static void show_all (); |
---|
[541] | 117 | static void show_container (const cmt_string& path = ""); |
---|
[16] | 118 | static void show_specified_strategies_for_all (); |
---|
[547] | 119 | static void show_paths (const CmtSystem::cmt_string_vector& arguments, ostream& out = cout); |
---|
[482] | 120 | // static void show_paths (); |
---|
[2] | 121 | static const cmt_string& get_project_file_name (); |
---|
| 122 | |
---|
[652] | 123 | static void fill_selection (int depth, ConstProjectPtrVector& path_selections); |
---|
| 124 | // static void fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections); |
---|
| 125 | static void fill_exclusion (ConstProjectPtrVector& path_exclusions); |
---|
[2] | 126 | |
---|
| 127 | static void broadcast (IProjectAction& action); |
---|
| 128 | static void reverse_broadcast (IProjectAction& action); |
---|
| 129 | static void scan_paths (PathScanner& scanner, PathScanner::actor& actor); |
---|
| 130 | static void scan_paths_for_package (PathScanner& scanner, const cmt_string& name); |
---|
| 131 | |
---|
[608] | 132 | static cmt_string find_in_cmt_paths (const cmt_string& path, bool realpath = false); |
---|
[2] | 133 | |
---|
[9] | 134 | static void fill_cmtpaths (cmt_string& buffer); |
---|
[3] | 135 | |
---|
[9] | 136 | static void start_visit (IProjectVisitor& visitor); |
---|
| 137 | |
---|
[2] | 138 | public: |
---|
| 139 | |
---|
| 140 | Project (); |
---|
| 141 | |
---|
| 142 | const cmt_string& get_name () const; |
---|
[8] | 143 | const cmt_string& get_release () const; |
---|
[525] | 144 | const cmt_string& get_container_name () const; |
---|
[41] | 145 | const cmt_string& get_container_version () const; |
---|
[525] | 146 | const cmt_string& get_container_path () const; |
---|
[526] | 147 | const Use& get_container () const; |
---|
[2] | 148 | const cmt_string& get_cmtpath () const; |
---|
[437] | 149 | const cmt_string& get_cmtpath_real () const; |
---|
[2] | 150 | const cmt_string& get_cmtpath_pwd () const; |
---|
| 151 | const cmt_string& get_cmtpath_source () const; |
---|
[9] | 152 | int get_children_size () const; |
---|
[273] | 153 | |
---|
| 154 | const CmtSystem::cmt_string_vector get_project_releases(const cmt_string& name) const; |
---|
| 155 | bool select_release(const cmt_string& name, const cmt_string& release, cmt_string& result); |
---|
| 156 | |
---|
[9] | 157 | Project* get_child (int index) const; |
---|
| 158 | bool visited () const; |
---|
| 159 | |
---|
[8] | 160 | void set_name (const cmt_string& name); |
---|
| 161 | void set_release (const cmt_string& release); |
---|
[525] | 162 | // void set_container (const cmt_string& container); |
---|
| 163 | void set_container_name (const cmt_string& name); |
---|
[41] | 164 | void set_container_version (const cmt_string& version); |
---|
[525] | 165 | void set_container_path (const cmt_string& path); |
---|
[2] | 166 | void set_cmtpath (const cmt_string& path); |
---|
[437] | 167 | void set_cmtpath_real (const cmt_string& path); |
---|
[2] | 168 | void set_cmtpath_pwd (const cmt_string& path); |
---|
| 169 | void set_cmtpath_source (const cmt_string& source); |
---|
[535] | 170 | void set_is_current (bool is_current); |
---|
| 171 | bool is_current () const; |
---|
[2] | 172 | void clear (); |
---|
| 173 | void configure (); |
---|
[79] | 174 | bool has_parents () const; |
---|
[36] | 175 | bool has_parent (Project* p) const; |
---|
| 176 | bool has_child (Project* p) const; |
---|
[9] | 177 | void add_parent (Project* p); |
---|
| 178 | void add_child (Project* p); |
---|
[535] | 179 | void erase_child (Project* p); |
---|
[2] | 180 | |
---|
[525] | 181 | void container_action (const CmtSystem::cmt_string_vector& words); |
---|
| 182 | // void container_action (const cmt_string& name, const cmt_string& version); |
---|
[3] | 183 | void use_action (const cmt_string& name, const cmt_string& release); |
---|
| 184 | |
---|
[581] | 185 | // Project& operator = (const Project& other); |
---|
[2] | 186 | bool operator == (const cmt_string& name) const; |
---|
| 187 | bool operator != (const cmt_string& name) const; |
---|
| 188 | |
---|
[550] | 189 | void show (PrintMode mode = Csh); // Csh is default for ArgParser::mode |
---|
| 190 | // void show (); |
---|
[16] | 191 | void show_specified_strategies () const; |
---|
[2] | 192 | |
---|
[15] | 193 | bool has_strategy (const StrategyDef* definition) const; |
---|
| 194 | bool is_specified (const StrategyDef* definition) const; |
---|
| 195 | bool get_strategy (const StrategyDef* definition) const; |
---|
| 196 | bool get_strategy (const cmt_string& name) const; |
---|
| 197 | void set_default_strategy (const cmt_string& name); |
---|
[16] | 198 | void set_strategy (const cmt_string& name, const cmt_string& value, const cmt_string& context); |
---|
| 199 | void set_strategy (StrategyDef* definition, bool b_value, const cmt_string& context); |
---|
[15] | 200 | void update_strategy (StrategyDef* definition, bool b_value); |
---|
| 201 | void update_strategy_from_children (StrategyDef* definition); |
---|
| 202 | void update_strategies_from_children (); |
---|
[272] | 203 | void set_author (const cmt_string& name); |
---|
| 204 | const cmt_string& get_author () const; |
---|
| 205 | void project_author_action (const CmtSystem::cmt_string_vector& words); |
---|
| 206 | // bool get_author (const cmt_string& name) const; |
---|
| 207 | |
---|
[295] | 208 | void visit (IProjectVisitor& visitor); |
---|
[470] | 209 | static void visit (IProjectVisitor& visitor, ProjectPtrVector& projects); |
---|
[515] | 210 | static void visit (const int offset, int& order, ProjectPtrVector& projects); |
---|
[272] | 211 | |
---|
[295] | 212 | // Use |
---|
| 213 | Use* get_use () const; |
---|
| 214 | void set_use (Use* use); |
---|
| 215 | |
---|
[330] | 216 | cmt_vector <cmt_string> m_extra_lines; |
---|
| 217 | |
---|
[2] | 218 | private: |
---|
[9] | 219 | |
---|
[581] | 220 | Project& operator = (const Project& other); |
---|
| 221 | Project (const Project& other); |
---|
| 222 | |
---|
[9] | 223 | void fill_cmtpath (cmt_string& buffer); |
---|
| 224 | |
---|
[2] | 225 | cmt_string m_name; |
---|
[272] | 226 | cmt_string m_author; |
---|
[8] | 227 | cmt_string m_release; |
---|
[525] | 228 | cmt_string m_container_name; |
---|
[41] | 229 | cmt_string m_container_version; |
---|
[525] | 230 | cmt_string m_container_path; |
---|
| 231 | Use m_container; |
---|
[2] | 232 | |
---|
[9] | 233 | ProjectPtrVector m_parents; |
---|
| 234 | ProjectPtrVector m_children; |
---|
[2] | 235 | |
---|
[9] | 236 | bool m_visited; |
---|
[470] | 237 | int m_visits; |
---|
[471] | 238 | int m_order; |
---|
[535] | 239 | bool m_is_current; |
---|
[9] | 240 | |
---|
[2] | 241 | cmt_string m_cmtpath; |
---|
[437] | 242 | cmt_string m_cmtpath_real; |
---|
[2] | 243 | cmt_string m_cmtpath_pwd; |
---|
| 244 | cmt_string m_cmtpath_source; |
---|
| 245 | |
---|
| 246 | bool m_configured; |
---|
| 247 | |
---|
[15] | 248 | cmt_vector <Strategy> m_strategies; |
---|
[295] | 249 | |
---|
| 250 | Use* m_use; |
---|
[2] | 251 | }; |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | #endif |
---|