[1] | 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 | |
---|
| 92 | void fill_includes_macro (cmt_string& buffer) const; |
---|
| 93 | void fill_macro (cmt_string& buffer, const cmt_string& suffix) const; |
---|
| 94 | void fill_standard_macros (cmt_string& buffer) const; |
---|
| 95 | void build_library_links (const cmt_string& cmtinstallarea, |
---|
| 96 | const cmt_string& tag, |
---|
| 97 | const cmt_string& shlibsuffix, |
---|
| 98 | const cmt_string& symlinkcmd) const; |
---|
| 99 | |
---|
| 100 | bool get_all_clients (const cmt_string& to_name); |
---|
| 101 | |
---|
| 102 | bool get_paths (Use* to, UsePtrVector& list); |
---|
| 103 | |
---|
| 104 | bool located () const; |
---|
| 105 | |
---|
| 106 | void change_path (const cmt_string& path); |
---|
| 107 | void set_auto_imports (State new_state); |
---|
| 108 | void set_native_version (bool state); |
---|
| 109 | bool has_native_version () const; |
---|
| 110 | |
---|
| 111 | Package* get_package () const; |
---|
| 112 | const cmt_string& get_package_name () const; |
---|
| 113 | void set_package_name (const cmt_string& name); |
---|
| 114 | |
---|
| 115 | int get_index () const; |
---|
| 116 | |
---|
| 117 | void show_cycles (); |
---|
| 118 | |
---|
| 119 | void push_scope_section (ScopeType type); |
---|
| 120 | void pop_scope_section (); |
---|
| 121 | void close_scope_sections (); |
---|
| 122 | |
---|
| 123 | ScopeType get_current_scope () const; |
---|
| 124 | |
---|
| 125 | // Public attributes |
---|
| 126 | public: |
---|
| 127 | |
---|
| 128 | cmt_string specified_version; /* idem */ |
---|
| 129 | cmt_string specified_path; /* idem */ |
---|
| 130 | cmt_string version_alias; |
---|
| 131 | cmt_string path_alias; |
---|
| 132 | cmt_string author; /* idem */ |
---|
| 133 | cmt_string manager; /* idem */ |
---|
| 134 | |
---|
| 135 | cmt_string path; /* expanded path */ |
---|
| 136 | cmt_string version; /* idem */ |
---|
| 137 | cmt_string real_path; |
---|
| 138 | CmtDirStyle style; /* May be cmt or mgr */ |
---|
| 139 | |
---|
| 140 | cmt_string prefix; /* upper case copy of package */ |
---|
| 141 | bool done; /* true when requirements file has |
---|
| 142 | already been read */ |
---|
| 143 | bool discarded; /* discarded by version strategy */ |
---|
| 144 | bool selected; /* used for recursive access */ |
---|
| 145 | |
---|
| 146 | State auto_imports; |
---|
| 147 | |
---|
| 148 | Include::IncludeVector includes; |
---|
| 149 | cmt_string include_path; |
---|
| 150 | Script::ScriptVector scripts; |
---|
| 151 | ApplyPattern::ApplyPatternVector apply_patterns; |
---|
| 152 | IgnorePattern::IgnorePatternVector ignore_patterns; |
---|
| 153 | |
---|
| 154 | // Private methods |
---|
| 155 | private: |
---|
| 156 | void clear (); |
---|
| 157 | int reach_package (const cmt_string& current_path); |
---|
| 158 | void select (); |
---|
| 159 | void unselect (); |
---|
| 160 | bool is_selected (); |
---|
| 161 | bool is_client (const cmt_string& package, |
---|
| 162 | const cmt_string& version); |
---|
| 163 | void show_sub_uses (const cmt_string& request, bool skip_discarded = false); |
---|
| 164 | bool select_alternate (); |
---|
| 165 | Use* get_selected_version (); |
---|
| 166 | Use* set_selected_version (Use* selected_use); |
---|
| 167 | |
---|
| 168 | static bool need_new (const cmt_string& path, |
---|
| 169 | const cmt_string& package, |
---|
| 170 | const cmt_string& version, |
---|
| 171 | Use** old_use, |
---|
| 172 | Use* context_use); |
---|
| 173 | |
---|
| 174 | bool get_all_clients (Use* to, |
---|
| 175 | const cmt_string& result, |
---|
| 176 | cmt_map <cmt_string, Use*>& all_clients, |
---|
| 177 | cmt_map <cmt_string, Use*>& all_clients_ok); |
---|
| 178 | |
---|
| 179 | // Private attributes |
---|
| 180 | private: |
---|
| 181 | |
---|
| 182 | Package* m_package; |
---|
| 183 | //cmt_string m_package_name; /* directly read from requirements */ |
---|
| 184 | |
---|
| 185 | bool m_located; |
---|
| 186 | bool m_has_native_version; |
---|
| 187 | |
---|
| 188 | UsePtrVector sub_uses; |
---|
| 189 | cmt_vector<ScopeType> sub_use_scopes; |
---|
| 190 | cmt_vector<State> sub_use_auto_imports; |
---|
| 191 | |
---|
| 192 | ScopeType initial_scope; |
---|
| 193 | cmt_vector<ScopeSection> scope_sections; |
---|
| 194 | |
---|
| 195 | CmtSystem::cmt_string_vector alternate_versions; |
---|
| 196 | CmtSystem::cmt_string_vector alternate_paths; |
---|
| 197 | |
---|
| 198 | CmtSystem::cmt_string_vector requests; |
---|
| 199 | |
---|
| 200 | int m_index; // Position within the ordered list of uses |
---|
| 201 | |
---|
| 202 | friend class UseProjectAction; |
---|
| 203 | }; |
---|
| 204 | |
---|
| 205 | class Package |
---|
| 206 | { |
---|
| 207 | public: |
---|
| 208 | |
---|
| 209 | typedef cmt_map<cmt_string, Package> PackageMap; |
---|
| 210 | typedef cmt_vector<Package> PackageVector; |
---|
| 211 | |
---|
| 212 | static Package* find (const cmt_string& name); |
---|
| 213 | static Package* add (const cmt_string& name); |
---|
| 214 | |
---|
| 215 | static PackageVector& packages (); |
---|
| 216 | static PackageMap& package_map (); |
---|
| 217 | |
---|
| 218 | static void clear_all (); |
---|
| 219 | |
---|
| 220 | public: |
---|
| 221 | |
---|
| 222 | Package (); |
---|
| 223 | ~Package (); |
---|
| 224 | |
---|
| 225 | const cmt_string& get_name () const; |
---|
| 226 | void add_use (Use* use); |
---|
| 227 | void remove_use (Use* use); |
---|
| 228 | Use::UsePtrVector& get_uses (); |
---|
| 229 | |
---|
| 230 | bool is_cmt (); |
---|
| 231 | |
---|
| 232 | private: |
---|
| 233 | bool m_is_cmt; |
---|
| 234 | |
---|
| 235 | cmt_string m_name; |
---|
| 236 | Use::UsePtrVector m_uses; |
---|
| 237 | }; |
---|
| 238 | |
---|
| 239 | #endif |
---|