packagecmd.h

00001 
00002 // Name:        packagecmd.h
00003 // Purpose:     wxPackageCommand, wxPackageCommandArray, wxPackageCommandSet
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     2006-13-07
00007 // RCS-ID:      $Id: packagecmd.h,v 1.3 2007/01/28 15:56:11 frm Exp $
00008 // Copyright:   (c) Julian Smart, Francesco Montorsi, Daniel J. Lauk
00009 // Licence:     wxWidgets licence
00011 
00012 #ifndef _PACKAGECMD_H_
00013 #define _PACKAGECMD_H_
00014 
00015 // Includes
00016 #include "wx/tokenzr.h"
00017 #include "wx/process.h"
00018 #include "wxp/compiler.h"
00019 #include "wxp/packageopt.h"
00020 
00021 
00022 class wxPackageCommand;
00023 class wxPackageCommandSet;
00024 
00025 extern wxPackageCommand wxEmptyPackageCommand;
00026 
00027 
00028 // ----------------------------------------------------------------------------
00029 // wxPackageCommand
00030 // ----------------------------------------------------------------------------
00031 
00035 class wxPackageCommand : public wxObject
00036 {
00037     DECLARE_DYNAMIC_CLASS(wxPackageCommand)
00038 
00039 public:
00040 
00042     wxPackageCommand(const wxString &str = wxEmptyString,
00043                      const wxString &path = wxEmptyString,
00044                      const wxPackageCondition &cond = wxEmptyPackageCondition)
00045         : m_strCmd(str), m_strPath(path), m_cond(cond) {}
00046 
00047     wxPackageCommand& operator= (const wxString &cmd)
00048         { m_strCmd=cmd; return *this; }
00049 
00050 public:     // keywords
00051 
00052     void AddKeyword(const wxString &name, const wxString &value)
00053         { m_hashmapKeywords[name]=value; }
00054     void AddKeywords(const wxArrayString &names, const wxArrayString &values)
00055     {
00056         wxASSERT(names.GetCount()==values.GetCount());
00057         for (size_t i=0; i<names.GetCount(); i++)
00058             AddKeyword(names[i], values[i]);
00059     }
00060     void AddKeywords(const wxStringHashMap &hash)
00061     {
00062         for (wxStringHashMap::const_iterator it = hash.begin(); it != hash.end(); it++)
00063             AddKeyword(it->first, it->second);
00064     }
00065 
00066 public:     // misc
00067 
00068     // cast operator
00069     operator wxString() const
00070         { return m_strCmd; }
00071 
00072     bool IsOk() const
00073     {
00074         return !m_strCmd.IsEmpty() &&
00075                m_cond.IsOk();
00076     }
00077 
00078     void UpdateWorkingDirectory(const wxString &decompressionpath) const;
00079     long Run(wxProcess *proc = NULL) const;
00080 
00081 public:     // getters
00082 
00083     wxPackageCondition &GetCondition()
00084         { return m_cond; }
00085     const wxPackageCondition &GetCondition() const
00086         { return m_cond; }
00087 
00088     wxString GetCommand() const
00089         { return wxDoStringSubstitution(m_strCmd, m_hashmapKeywords); }
00090     wxString GetWorkingPath() const
00091         { return wxDoStringSubstitution(m_strPath, m_hashmapKeywords); }
00092 
00093     wxString GetProgram() const;
00094     wxString GetProgramWithPath(const wxCompilerSettings &) const;
00095     wxString GetProgramArguments() const;
00096 
00097     wxStringHashMap &GetKeywords()
00098         { return m_hashmapKeywords; }
00099 
00100 public:     // setters
00101 
00102     void SetCondition(const wxPackageCondition &cnd)
00103         { m_cond=cnd; }
00104     void SetCommand(const wxString &cmd)
00105         { m_strCmd=cmd; }
00106     void SetWorkingPath(const wxString &path)
00107         { m_strPath=path; }
00108 
00109 protected:
00110     wxString m_strCmd;
00111 
00114     wxString m_strPath;
00115 
00117     wxPackageCondition m_cond;
00118 
00121     wxStringHashMap m_hashmapKeywords;
00122 };
00123 
00124 // the array
00125 WX_DECLARE_OBJARRAY(wxPackageCommand, wxPackageCommandArrayHelper);
00126 
00127 
00128 
00129 // ----------------------------------------------------------------------------
00130 // wxPackageCommandArray
00131 // ----------------------------------------------------------------------------
00132 
00135 class wxPackageCommandArray : public wxPackageCommandArrayHelper
00136 {
00137 public:
00138 
00140     wxPackageCommandArray(wxPackageBuildSystemStage s = wxPBSS_BUILD)
00141         : m_nSelectedTarget(0), m_stage(s) {}
00142 
00143 
00144 public:     // miscellaneous
00145 
00146     bool IsOk() const
00147     {
00148         for (size_t i=0; i<GetCount(); i++)
00149             if (!Item(i).IsOk())
00150                 return false;
00151         return true;
00152     }
00153 
00155     void AddKeywords(const wxArrayString &names, const wxArrayString &values)
00156     {
00157         for (size_t i=0; i<GetCount(); i++)
00158             Item(i).AddKeywords(names, values);
00159     }
00160     void AddKeywords(const wxStringHashMap &hash)
00161     {
00162         for (size_t i=0; i<GetCount(); i++)
00163             Item(i).AddKeywords(hash);
00164     }
00165 
00166 public:     // getters
00167 
00169     wxArrayString &GetTargets()
00170         { return m_arrTargets; }
00171     wxArrayString GetTargets() const
00172         { return m_arrTargets; }
00173     wxString GetTargetsStr() const
00174                 { return wxArray2String(m_arrTargets); }
00175 
00176     wxPackageBuildSystemStage GetStage() const
00177         { return m_stage; }
00178 
00180     wxPackageCommand GetSubstitutedCmd(size_t n) const;
00181 
00184     wxPackageCommandArray GetValidCommandsFor(const wxPackage &) const;
00185 
00188     wxString GetSelectedTarget() const
00189         { return m_arrTargets[m_nSelectedTarget]; }
00190 
00191 public:     // setters
00192 
00193     void SetTargets(const wxString &str)
00194         { m_arrTargets = wxString2Array(str); }
00195     void SetTargets(const wxArrayString &str)
00196         { m_arrTargets = str; }
00197 
00198     void SetSelectedTarget(size_t n)
00199     { 
00200         // the || n == 0 part is when an invalid package contains no
00201         // targets: in that case the value zero is "valid"
00202         wxASSERT(n < m_arrTargets.GetCount() || n == 0); 
00203         m_nSelectedTarget=n; 
00204     }
00205 
00206     void CopyTargets(const wxPackageCommandArray &arr)
00207     {
00208         m_arrTargets = arr.m_arrTargets;
00209         m_nSelectedTarget = arr.m_nSelectedTarget;
00210     }
00211 
00212 protected:
00213 
00215     wxArrayString m_arrTargets;
00216 
00218     size_t m_nSelectedTarget;
00219 
00221     wxPackageBuildSystemStage m_stage;
00222 };
00223 
00224 
00225 
00226 // ----------------------------------------------------------------------------
00227 // wxPackageCommandSet
00228 // ----------------------------------------------------------------------------
00229 
00230 class wxPackageCommandSet : public wxPackageCommandArray
00231 {
00232 public:
00233     wxPackageCommandSet() {}
00234 
00235 public:     // getters
00236 
00237     wxArrayString GetVars() const
00238         { return m_vars; }
00239     wxPackageBuildSystemType GetBuildSystemType() const
00240         { return m_buildSystemType; }
00241 
00243     wxString GetDescription() const
00244         { return m_strDesc; }
00245 
00246 public:     // setters
00247 
00248     void SetVars(const wxString &var)
00249         { m_vars = wxString2Array(var); }
00250     void SetBuildSystemType(wxPackageBuildSystemType t)
00251         { m_buildSystemType=t; }
00252     void SetDescription(const wxString &str)
00253         { m_strDesc=str; }
00254 
00255 public:     // misc
00256 
00257     bool IsOk() const
00258     {
00259         return m_buildSystemType != wxPBST_INVALID &&
00260                wxPackageCommandArray::IsOk();
00261     }
00262 
00266     bool IsUsedBy(const wxPackageCommandArray *arrays, wxStringHashMap &touse) const;
00267 
00268 protected:
00269     wxArrayString m_vars;
00270     wxPackageBuildSystemType m_buildSystemType;
00271     wxString m_strDesc;
00272 };
00273 
00274 
00275 #endif      // _PACKAGECMD_H_
00276 

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1