packageopt.h

00001 
00002 // Name:        packageopt.h
00003 // Purpose:     wxPackageCommandOption, wxPackageCommandOptionArray
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     2006-1-07
00007 // RCS-ID:      $Id: packageopt.h,v 1.5 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 _PACKAGEOPT_H_
00013 #define _PACKAGEOPT_H_
00014 
00015 // Includes
00016 #include "wx/tokenzr.h"
00017 #include "wxp/wxputils.h"
00018 #include "wxp/compiler.h"
00019 #include "wxp/packageutils.h"
00020 
00021 // Forward declarations
00022 class wxPackageCommandOption;
00023 class wxPackageCommandOptionArray;
00024 class wxPackageCommandArray;
00025 class wxPackageCondition;
00026 class wxPackage;
00027 
00028 
00029 
00030 // ----------------------------------------------------------------------------
00031 // enums
00032 // ----------------------------------------------------------------------------
00033 
00035 enum wxPackageCommandOptionCategory
00036 {
00037     wxPCOC_INVALID = -1,
00038 
00039     wxPCOC_LISTED_VALUES,       
00040     wxPCOC_DIRECTORY,           
00041     wxPCOC_FILE,                
00042     wxPCOC_STRING,              
00043 
00044     wxPCOC_MAX
00045 };
00046 
00047 extern wxPackageCommandOption wxEmptyPackageCommandOption;
00048 extern wxPackageCommandOptionArray wxEmptyPackageCommandOptionArray;
00049 extern wxPackageCommandArray wxEmptyPackageCommandArray;
00050 
00051 wxDEFINE_STRING2ENUM(PackageCommandOptionCategory)
00052 
00053 
00054 
00055 // ----------------------------------------------------------------------------
00056 // wxPackageCommandOption
00057 // ----------------------------------------------------------------------------
00058 
00059 
00060 
00061 
00062 class wxPackageCommandOption: public wxObject
00063 {
00064     DECLARE_DYNAMIC_CLASS(wxPackageCommandOption)
00065 
00066 public:
00067 
00069     wxPackageCommandOption(
00070              const wxString &name = wxEmptyString,
00071              const wxString &allowedvalues = wxEmptyString,
00072              const wxString &value = wxEmptyString,
00073              const wxString &def = wxEmptyString,
00074              const wxString &valuesdesc = wxEmptyString,
00075              const wxString &desc = wxEmptyString,
00076              const wxString &grp = wxEmptyString,
00077              wxPackageCommandOptionCategory cat = wxPCOC_LISTED_VALUES,
00078              const wxPackageCondition &cnd = wxEmptyPackageCondition)
00079              : m_strName(name),
00080                m_strAllowedValues(allowedvalues),
00081                m_strDefValue(def), m_strValue(value), m_strDesc(desc),
00082                m_strGroup(grp), m_strValuesDesc(valuesdesc),
00083                m_nCat(cat), m_cond(cnd) {}
00084 
00086     wxPackageCommandOption(
00087              const wxString &name,
00088              bool value,
00089              bool def = true,
00090              const wxString &desc = wxEmptyString,
00091              const wxString &grp = wxEmptyString,
00092              const wxPackageCondition &cnd = wxEmptyPackageCondition)
00093              : m_strName(name),
00094                m_strAllowedValues(wxT("1,0")),
00095                m_strDefValue(def ? wxT("1") : wxT("0")),
00096                m_strValue(value ? wxT("1") : wxT("0")),
00097                m_strDesc(desc),
00098                m_strGroup(grp),
00099                m_nCat(wxPCOC_LISTED_VALUES), m_cond(cnd) {}
00100 
00101     virtual ~wxPackageCommandOption() {}
00102 
00103 public:     // miscellaneous
00104 
00107     void AutodetectCategory();
00108 
00110     void ResetToDefault()
00111         { m_strValue = m_strDefValue; }
00112 
00113     bool operator==(const wxPackageCommandOption &opt) const;
00114     bool operator!=(const wxPackageCommandOption &opt) const
00115         { return !(*this == opt); }
00116 
00117 public:     // getters
00118 
00119     wxString GetName() const
00120         { return m_strName; }
00121     wxString GetAllowedValues() const
00122         { return m_strAllowedValues; }
00123     wxString GetDefaultValue() const
00124         { return m_strDefValue; }
00125     wxString GetValue() const
00126         { return m_strValue; }
00127     wxString GetValueDesc() const
00128         { return m_strValuesDesc; }
00129 
00130     wxString GetDescription() const
00131         { return m_strDesc; }
00132     wxString GetGroup() const
00133         { return m_strGroup; }
00134 
00135     wxPackageCommandOptionCategory GetCategory() const
00136         { return m_nCat; }
00137     wxString GetCategoryStr() const
00138         { return wxPackageCommandOptionCategory2String(m_nCat); }
00139 
00140     bool GetBooleanValue() const
00141     {
00142         wxASSERT(IsBoolean());
00143         return GetValue() == wxT("1");
00144     }
00145 
00146 public:     // wxArrayString-friendly getters
00147 
00148     wxArrayString GetAllowedValuesArray() const
00149         { return wxString2Array(m_strAllowedValues); }
00150     wxArrayString GetAllowedValuesDescArray() const
00151         { return wxString2Array(m_strValuesDesc); }
00152     size_t GetDefaultValueIndex() const
00153         { return GetAllowedValuesArray().Index(GetDefaultValue()); }
00154     size_t GetValueIndex() const
00155         { return GetAllowedValuesArray().Index(GetValue()); }
00156 
00157     const wxPackageCondition &GetCondition() const
00158         { return m_cond; }
00159     wxPackageCondition &GetCondition()
00160         { return m_cond; }
00161 
00162 public:     // setters
00163 
00164     void SetValue(const wxString &value)
00165         { m_strValue=value; }
00166     void SetDefaultValue(const wxString &value)
00167         { m_strDefValue=value; }
00168 
00169     void SetCondition(const wxPackageCondition &c)
00170         { m_cond=c; }
00171 
00172 public:     // checkers
00173 
00176     bool IsBoolean() const
00177         { return m_strAllowedValues == wxT("0,1") ||
00178                  m_strAllowedValues == wxT("1,0"); }
00179 
00181     bool IsOk() const;
00182 
00184     bool IsChanged() const
00185         { return m_strValue != m_strDefValue; }
00186 
00187 protected:
00188     wxString m_strName, m_strAllowedValues, m_strDefValue, m_strValue;
00189     wxString m_strDesc, m_strGroup, m_strValuesDesc;
00190 
00192     wxPackageCommandOptionCategory m_nCat;
00193 
00195     wxPackageCondition m_cond;
00196 };
00197 
00198 // the array
00199 WX_DECLARE_OBJARRAY(wxPackageCommandOption, wxPackageCommandOptionArrayHelper);
00200 
00201 
00202 
00203 
00204 // ----------------------------------------------------------------------------
00205 // wxPackageCommandOptionArray
00206 // ----------------------------------------------------------------------------
00207 
00209 class wxPackageCommandOptionArray : public wxPackageCommandOptionArrayHelper
00210 {
00211 public:
00212 
00214     wxPackageCommandOptionArray() { m_bDirty=false; }
00215     wxPackageCommandOptionArray(const wxPackageCommandOptionArray &arr)
00216         : wxPackageCommandOptionArrayHelper(arr), m_bDirty(arr.m_bDirty) {}
00217 
00218     wxPackageCommandOptionArray &operator=(const wxPackageCommandOptionArray &arr)
00219     {
00220         *((wxPackageCommandOptionArrayHelper*)this)=arr;
00221         m_bDirty=arr.m_bDirty;
00222         m_strDesc=arr.m_strDesc;
00223         return *this;
00224     }
00225 
00226 public:     // miscellaneous
00227 
00228     // define & implement IsOk(), IndexByName(), ItemByName(), Contains()
00229     // and ContainsItemNamed() functions
00230     WX_DECLARE_STD_OBJARRAY_HELPERS(wxPackageCommandOption, 
00231                                     wxEmptyPackageCommandOption);
00232 
00234     int IndexByGroup(const wxString &grpname) const
00235     {
00236         for (size_t i=0; i<GetCount(); i++)
00237             if (Item(i).GetGroup() == grpname)
00238                 return i;
00239         return wxNOT_FOUND;
00240     }
00241 
00242     bool Add(const wxPackageCommandOption &opt, size_t copies = 1)
00243     {
00244         if (IndexByName(opt.GetName()) == wxNOT_FOUND)
00245         {
00246             wxPackageCommandOptionArrayHelper::Add(opt, copies);
00247             return true;
00248         }
00249 
00250         wxLogWarning(wxT("Discarding duplicate option named '%s'"),
00251                      opt.GetName().c_str());
00252         return false;
00253     }
00254 
00256     void ResetToDefaults()
00257     {
00258         for (size_t i=0; i<GetCount(); i++)
00259             Item(i).ResetToDefault();
00260     }
00261 
00265     bool UpdateOption(const wxPackageCommandOption &opt);
00266 
00268     bool Contains(const wxPackageCommandOptionArray &arr) const;
00269 
00272     bool Remove(const wxPackageCommandOptionArray &arr);
00273 
00274 
00275 public:     // getters
00276 
00277     wxPackageCommandOption &ItemByGroup(const wxString &grpname)
00278     {
00279         int n = IndexByGroup(grpname);
00280         if (n != wxNOT_FOUND)
00281             return wxPackageCommandOptionArrayHelper::Item(n);
00282         return wxEmptyPackageCommandOption;
00283     }
00284 
00286     wxArrayString GetAllOptionGroups() const;
00287 
00290     wxArrayString GetOptionGroups(long stages = wxGetFullPackageBuildSystemStageList()) const;
00291 
00293     wxPackageCommandOptionArray GetChangedOptions() const;
00294 
00296     wxString GetAsList() const;
00297 
00299     wxString GetDescription() const
00300         { return m_strDesc; }
00301 
00303     wxPackageCondition GetCommonCondition() const;
00304 
00305 public:     // setters
00306 
00307     void SetDescription(const wxString &str)
00308         { m_strDesc=str; }
00309 
00310 public:     // substitution helpers
00311 
00314     wxStringHashMap GetSubstitutionOptionsHashMap(long flags, 
00315                 const wxPackageCondition &cond = wxEmptyPackageCondition) const;
00316 
00318     wxString SubstituteOptions(const wxString &str, long flags,
00319                                const wxPackageCondition &cond = wxEmptyPackageCondition) const
00320         { return wxDoStringSubstitution(str, 
00321                     GetSubstitutionOptionsHashMap(flags, cond)); }
00322 
00323 public:     // dirty status
00324 
00325     void SetDirty(bool d = true)
00326         { m_bDirty = d; }
00327     bool IsDirty() const
00328         { return m_bDirty; }
00329 
00330 protected:      // internal helpers
00331 
00332     wxStringHashMap GetGroupNamesHashMap(long flags, const wxPackageCondition &cond) const;
00333     wxStringHashMap GetTypeNamesHashMap(long flags, const wxPackageCondition &cond) const;
00334 
00335 protected:
00336     // have options been changed?
00337     bool m_bDirty;
00338 
00339     // description of this array
00340     wxString m_strDesc;
00341 };
00342 
00343 
00344 #endif      // _PACKAGEOPT_H_
00345 

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