[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; |
---|
| 89 | virtual void post (Project* p) = 0; |
---|
| 90 | }; |
---|
| 91 | |
---|
[2] | 92 | class Project |
---|
| 93 | { |
---|
| 94 | public: |
---|
| 95 | |
---|
| 96 | typedef cmt_vector<Project> ProjectVector; |
---|
[9] | 97 | typedef cmt_vector<Project*> ProjectPtrVector; |
---|
[2] | 98 | |
---|
[79] | 99 | static bool create (const cmt_string& name, |
---|
[22] | 100 | const cmt_string& release, |
---|
| 101 | const cmt_string& path); |
---|
[2] | 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 (); |
---|
[8] | 106 | static Project* add (const cmt_string& name, |
---|
| 107 | const cmt_string& release); |
---|
[2] | 108 | |
---|
| 109 | static ProjectVector& projects (); |
---|
| 110 | static void clear_all (); |
---|
| 111 | static void show_all (); |
---|
[16] | 112 | static void show_specified_strategies_for_all (); |
---|
[2] | 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 | |
---|
[9] | 125 | static void fill_cmtpaths (cmt_string& buffer); |
---|
[3] | 126 | |
---|
[9] | 127 | static void start_visit (IProjectVisitor& visitor); |
---|
| 128 | |
---|
[2] | 129 | public: |
---|
| 130 | |
---|
| 131 | Project (); |
---|
| 132 | |
---|
| 133 | const cmt_string& get_name () const; |
---|
[8] | 134 | const cmt_string& get_release () const; |
---|
[41] | 135 | const cmt_string& get_container () const; |
---|
| 136 | const cmt_string& get_container_version () const; |
---|
[2] | 137 | const cmt_string& get_cmtpath () const; |
---|
| 138 | const cmt_string& get_cmtpath_pwd () const; |
---|
| 139 | const cmt_string& get_cmtpath_source () const; |
---|
[9] | 140 | int get_children_size () const; |
---|
[273] | 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 | |
---|
[9] | 145 | Project* get_child (int index) const; |
---|
| 146 | bool visited () const; |
---|
| 147 | |
---|
[8] | 148 | void set_name (const cmt_string& name); |
---|
| 149 | void set_release (const cmt_string& release); |
---|
[41] | 150 | void set_container (const cmt_string& container); |
---|
| 151 | void set_container_version (const cmt_string& version); |
---|
[2] | 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 (); |
---|
[79] | 157 | bool has_parents () const; |
---|
[36] | 158 | bool has_parent (Project* p) const; |
---|
| 159 | bool has_child (Project* p) const; |
---|
[9] | 160 | void add_parent (Project* p); |
---|
| 161 | void add_child (Project* p); |
---|
[2] | 162 | |
---|
[41] | 163 | void container_action (const cmt_string& name, const cmt_string& version); |
---|
[3] | 164 | void use_action (const cmt_string& name, const cmt_string& release); |
---|
| 165 | |
---|
[2] | 166 | Project& operator = (const Project& other); |
---|
| 167 | bool operator == (const cmt_string& name) const; |
---|
| 168 | bool operator != (const cmt_string& name) const; |
---|
| 169 | |
---|
[9] | 170 | void show (); |
---|
[16] | 171 | void show_specified_strategies () const; |
---|
[2] | 172 | |
---|
[15] | 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); |
---|
[16] | 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); |
---|
[15] | 180 | void update_strategy (StrategyDef* definition, bool b_value); |
---|
| 181 | void update_strategy_from_children (StrategyDef* definition); |
---|
| 182 | void update_strategies_from_children (); |
---|
[272] | 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 | |
---|
[295] | 188 | void visit (IProjectVisitor& visitor); |
---|
[272] | 189 | |
---|
[295] | 190 | // Use |
---|
| 191 | Use* get_use () const; |
---|
| 192 | void set_use (Use* use); |
---|
| 193 | |
---|
[2] | 194 | private: |
---|
[9] | 195 | |
---|
| 196 | void fill_cmtpath (cmt_string& buffer); |
---|
| 197 | |
---|
[2] | 198 | cmt_string m_name; |
---|
[272] | 199 | cmt_string m_author; |
---|
[8] | 200 | cmt_string m_release; |
---|
[41] | 201 | cmt_string m_container; |
---|
| 202 | cmt_string m_container_version; |
---|
[2] | 203 | |
---|
[9] | 204 | ProjectPtrVector m_parents; |
---|
| 205 | ProjectPtrVector m_children; |
---|
[2] | 206 | |
---|
[9] | 207 | bool m_visited; |
---|
| 208 | |
---|
[2] | 209 | cmt_string m_cmtpath; |
---|
| 210 | cmt_string m_cmtpath_pwd; |
---|
| 211 | cmt_string m_cmtpath_source; |
---|
| 212 | |
---|
| 213 | bool m_configured; |
---|
| 214 | |
---|
[15] | 215 | cmt_vector <Strategy> m_strategies; |
---|
[295] | 216 | |
---|
| 217 | Use* m_use; |
---|
[2] | 218 | }; |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | #endif |
---|