00001
00002
00003
00004
00005
00006
00007 #ifndef __cmt_project_h__
00008 #define __cmt_project_h__
00009
00010 #include "cmt_parser.h"
00011 #include "cmt_system.h"
00012 #include "cmt_awk.h"
00013
00014 class Project;
00015
00016 class StrategyDef
00017 {
00018 public:
00019 typedef cmt_vector <StrategyDef*> StrategyDefs;
00020
00021 cmt_string m_keyword;
00022 cmt_string m_name;
00023 cmt_string m_on_value;
00024 cmt_string m_off_value;
00025 bool m_default_value;
00026 bool m_priority_value;
00027
00028 const cmt_string& get_default_value () const;
00029 };
00030
00031 class Strategy
00032 {
00033 public:
00034 StrategyDef* m_definition;
00035 bool m_specified;
00036 bool m_specified_value;
00037 bool m_value;
00038 Tag* m_on_tag;
00039 Tag* m_off_tag;
00040 cmt_string m_context;
00041
00042 Strategy ();
00043 void clear ();
00044 void set (StrategyDef* definition, bool value, const cmt_string& project_name);
00045 void update (StrategyDef* definition, bool value, const cmt_string& project_name);
00046 };
00047
00048 class StrategyMgr
00049 {
00050 public:
00051 static StrategyMgr& instance ();
00052 static StrategyDef* find_strategy (const cmt_string& name);
00053 static bool get_default_strategy (const cmt_string& name);
00054 static bool get_priority_strategy (const cmt_string& name);
00055 static StrategyDef::StrategyDefs& get_definitions ();
00056
00057 private:
00058 StrategyMgr ();
00059 StrategyDef::StrategyDefs m_defs;
00060 };
00061
00062 class ProjectFactory : public IProjectFactory
00063 {
00064 public:
00065 static IProjectFactory& instance ();
00066
00067 public:
00068 void reset ();
00069 Project* create_project (const cmt_string& name,
00070 const cmt_string& path,
00071 const cmt_string& path_source,
00072 Project* parent);
00073
00074 };
00075
00076 class IProjectAction
00077 {
00078 public:
00079 virtual bool run (const Project& project) = 0;
00080 };
00081
00082 class IProjectVisitor
00083 {
00084 public:
00085 virtual void pre (Project* p) = 0;
00086 virtual void in (Project* p) = 0;
00087 virtual void post (Project* p) = 0;
00088 };
00089
00090 class Project
00091 {
00092 public:
00093
00094 typedef cmt_vector<Project> ProjectVector;
00095 typedef cmt_vector<Project*> ProjectPtrVector;
00096
00097 static void create (const cmt_string& name,
00098 const cmt_string& release,
00099 const cmt_string& path);
00100
00101 static Project* find_by_name (const cmt_string& name);
00102 static Project* find_by_cmtpath (const cmt_string& cmtpath);
00103 static Project* get_current ();
00104 static Project* add (const cmt_string& name,
00105 const cmt_string& release);
00106
00107 static ProjectVector& projects ();
00108 static void clear_all ();
00109 static void show_all ();
00110 static void show_specified_strategies_for_all ();
00111 static void show_paths ();
00112 static const cmt_string& get_project_file_name ();
00113
00114 static void fill_selection (int depth, CmtSystem::cmt_string_vector& path_selections);
00115
00116 static void broadcast (IProjectAction& action);
00117 static void reverse_broadcast (IProjectAction& action);
00118 static void scan_paths (PathScanner& scanner, PathScanner::actor& actor);
00119 static void scan_paths_for_package (PathScanner& scanner, const cmt_string& name);
00120
00121 static cmt_string find_in_cmt_paths (const cmt_string& path);
00122
00123 static void fill_cmtpaths (cmt_string& buffer);
00124
00125 static void start_visit (IProjectVisitor& visitor);
00126
00127 public:
00128
00129 Project ();
00130
00131 const cmt_string& get_name () const;
00132 const cmt_string& get_release () const;
00133 const cmt_string& get_container () const;
00134 const cmt_string& get_container_version () const;
00135 const cmt_string& get_cmtpath () const;
00136 const cmt_string& get_cmtpath_pwd () const;
00137 const cmt_string& get_cmtpath_source () const;
00138 int get_children_size () const;
00139 Project* get_child (int index) const;
00140 bool visited () const;
00141
00142 void set_name (const cmt_string& name);
00143 void set_release (const cmt_string& release);
00144 void set_container (const cmt_string& container);
00145 void set_container_version (const cmt_string& version);
00146 void set_cmtpath (const cmt_string& path);
00147 void set_cmtpath_pwd (const cmt_string& path);
00148 void set_cmtpath_source (const cmt_string& source);
00149 void clear ();
00150 void configure ();
00151 bool has_parent (Project* p) const;
00152 bool has_child (Project* p) const;
00153 void add_parent (Project* p);
00154 void add_child (Project* p);
00155
00156 void container_action (const cmt_string& name, const cmt_string& version);
00157 void use_action (const cmt_string& name, const cmt_string& release);
00158
00159 Project& operator = (const Project& other);
00160 bool operator == (const cmt_string& name) const;
00161 bool operator != (const cmt_string& name) const;
00162
00163 void show ();
00164 void show_specified_strategies () const;
00165
00166 bool has_strategy (const StrategyDef* definition) const;
00167 bool is_specified (const StrategyDef* definition) const;
00168 bool get_strategy (const StrategyDef* definition) const;
00169 bool get_strategy (const cmt_string& name) const;
00170 void set_default_strategy (const cmt_string& name);
00171 void set_strategy (const cmt_string& name, const cmt_string& value, const cmt_string& context);
00172 void set_strategy (StrategyDef* definition, bool b_value, const cmt_string& context);
00173 void update_strategy (StrategyDef* definition, bool b_value);
00174 void update_strategy_from_children (StrategyDef* definition);
00175 void update_strategies_from_children ();
00176
00177 void visit (IProjectVisitor& visitor);
00178
00179 private:
00180
00181 void fill_cmtpath (cmt_string& buffer);
00182
00183 cmt_string m_name;
00184 cmt_string m_release;
00185 cmt_string m_container;
00186 cmt_string m_container_version;
00187
00188 ProjectPtrVector m_parents;
00189 ProjectPtrVector m_children;
00190
00191 bool m_visited;
00192
00193 cmt_string m_cmtpath;
00194 cmt_string m_cmtpath_pwd;
00195 cmt_string m_cmtpath_source;
00196
00197 bool m_configured;
00198
00199 cmt_vector <Strategy> m_strategies;
00200 };
00201
00202
00203 #endif