wxp.h

00001 
00002 // Name:        wxp.h
00003 // Purpose:     wxPackageXML, wxIfNodeListManager, wxPresetXMLDescriptor,
00004 //              wxPackageRepositoryXMLDescriptor
00005 // Author:      Francesco Montorsi
00006 // Modified by:
00007 // Created:     2006-06-29
00008 // RCS-ID:      $Id: wxp.h,v 1.4 2007/01/31 13:27:46 frm Exp $
00009 // Copyright:   (c) Francesco Montorsi
00010 // Licence:     wxWidgets licence
00012 
00013 #ifndef _WXP_H_
00014 #define _WXP_H_
00015 
00016 // Includes
00017 #include <wx/xml/xml.h>
00018 #include <wx/wfstream.h>
00019 #include "wxp/package.h"
00020 
00021 
00022 // the hashmap for storing OPTION presets
00023 WX_DECLARE_STRING_HASH_MAP( wxPackageCommandOptionArray,
00024                             wxPackageCommandOptionArrayHashMap );
00025 
00026 // the hashmap for storing COMMAND presets
00027 WX_DECLARE_STRING_HASH_MAP( wxPackageCommandSet,
00028                             wxPackageCommandSetHashMap );
00029 
00030 
00031 // ----------------------------------------------------------------------------
00032 // wxPackageXML
00033 // ----------------------------------------------------------------------------
00034 
00037 class wxPackageXML : public wxXmlDocument
00038 {
00039     DECLARE_DYNAMIC_CLASS(wxPackageXML)
00040 
00041 public:
00042 
00043     // -1 for m_nIndentationStep means "no indentation"
00044     wxPackageXML() { m_nIndentationStep=-1; }
00045     virtual ~wxPackageXML() {}
00046 
00047 
00048 public:     // indentation step (makes sense only in wxPackageXMLDescriptor currently!)
00049 
00050     int GetIndentationStep() const
00051         { return m_nIndentationStep; }
00052     void SetIndentationStep(int n)
00053         { m_nIndentationStep=n; }
00054 
00055 public:         // load helpers
00056 
00058     void HandleUnknownTag(wxXmlNode *node);
00059 
00061     wxPackageCommandOptionArray LoadOptions(const wxXmlNode *n);
00062 
00064     wxPackageCommandOption LoadOption(const wxXmlNode *n);
00065 
00067     wxPackageCondition LoadCondition(const wxXmlNode *n);
00068 
00070     wxPackageCommand LoadCommand(const wxXmlNode *n);
00071 
00073     wxString GetStrippedNodeContent(const wxXmlNode *n) const;
00074 
00075 public:         // save helpers
00076 
00080     wxXmlNode *AddChildIndentation(wxXmlNode *node, int level);
00081 
00085     wxXmlNode *AddSiblingIndentation(wxXmlNode *node, int level);
00086 
00088     wxXmlNode *InsertChildIndentation(wxXmlNode *node, wxXmlNode *before_node, int level);
00089 
00090     // NOTE: all the following functions create nodes which are then returned
00091     //       and not attached anywhere. They still take a "level" indentation 
00092     //       parameter because when creating nodes with subnodes, they need
00093     //       to indent the subnodes and thus need to know how many spaces to leave.
00094 
00096     wxXmlNode *SaveOption(const wxPackageCommandOption &opt, int level);
00097 
00099     wxXmlNode *SaveCommand(const wxPackageCommand &cmd, int level);
00100 
00102     wxXmlNode *SaveCondition(const wxPackageCondition &cond, int level);
00103 
00104 protected:
00105 
00107     int m_nIndentationStep;
00108 };
00109 
00110 
00111 
00112 // ----------------------------------------------------------------------------
00113 // wxIfNodeListManager
00114 // ----------------------------------------------------------------------------
00115 
00119 class wxIfNodeListManager
00120 {
00121 public:
00122     wxIfNodeListManager(wxPackageXML *xmldoc, wxXmlNode *parent)
00123         : m_parent(parent), m_doc(xmldoc) { m_previousif=NULL; }
00124 
00125     void SmartAppend(wxXmlNode *n, const wxPackageCondition &cnd, int level = 0);
00126     void SaveOptions(const wxPackageCommandOptionArray &arr, int level = 0);
00127     void SaveCommands(const wxPackageCommandArray &arr, int level = 0);
00128 
00129 
00130 protected:      // not changed anymore after initialization
00131 
00132     // the parent of all nodes appended
00133     wxXmlNode *m_parent;
00134 
00135     // the instance of the class which owns m_parent
00136     wxPackageXML *m_doc;
00137 
00138 protected:
00139 
00140     // the previous <if> node or NULL if previous node does not exist
00141     // or has a wxEmptyPackageCondition
00142     wxXmlNode *m_previousif;
00143 
00144     // the previous condition or wxEmptyPackageCondition if previous node
00145     // does not exist or has a wxEmptyPackageCondition
00146     wxPackageCondition m_previouscond;
00147 };
00148 
00149 
00150 
00151 // ----------------------------------------------------------------------------
00152 // wxPresetXMLDescriptor
00153 // ----------------------------------------------------------------------------
00154 
00156 class wxPresetXMLDescriptor : public wxPackageXML
00157 {
00158     DECLARE_DYNAMIC_CLASS(wxPresetXMLDescriptor)
00159 
00160 public:
00161     wxPresetXMLDescriptor() {}
00162     virtual ~wxPresetXMLDescriptor() {}
00163 
00164 
00165 public:         // static
00166 
00168     static wxPackageCommandOptionArrayHashMap s_hashmapOptions;
00169 
00171     static wxPackageCommandSetHashMap s_hashmapCommands;
00172 
00174     static wxArrayString GetCommandPresetNamesFor(wxPackageBuildSystemType type)
00175     {
00176         wxArrayString ret;
00177         wxPackageCommandSetHashMap::const_iterator it;
00178         for ( it = s_hashmapCommands.begin();
00179               it != s_hashmapCommands.end();
00180               it++ )
00181             if (it->second.GetBuildSystemType() == type)
00182                 ret.Add(it->first);
00183 
00184         return ret;
00185     }
00186 
00188     static wxArrayString GetOptionPresetNamesFor(wxPackageBuildSystemType type)
00189     {
00190         wxArrayString ret;
00191         wxPackageCommandOptionArrayHashMap::const_iterator it;
00192         for ( it = s_hashmapOptions.begin();
00193               it != s_hashmapOptions.end();
00194               it++ )
00195             if (it->second.GetCommonCondition().IsValidForBuildSys(type))
00196                 ret.Add(it->first);
00197 
00198         return ret;
00199     }
00200 
00201 
00202 #ifdef __WXDEBUG__
00203     static void Dump();
00204 #else
00205     static void Dump() {}
00206 #endif
00207 
00208 public:         // load & save
00209 
00212     bool Load(wxInputStream &stream);
00213 
00215     static bool Load(const wxString &filename);
00216 
00217 
00218     // NB: for these functions the "Save" name cannot be used as it is
00219     //     the name of a virtual function in the base class
00220 
00222     bool SavePresets(wxOutputStream &stream);
00223 
00225     static bool SavePresets(const wxString &filename);
00226 
00227 public:         // load helpers
00228 
00230     wxPackageCommandSet LoadCommandSet(const wxXmlNode *n);
00231 };
00232 
00233 
00234 // ----------------------------------------------------------------------------
00235 // wxPackageRepositoryXMLDescriptor
00236 // ----------------------------------------------------------------------------
00237 
00240 class wxPackageRepositoryXMLDescriptor : public wxPackageXML
00241 {
00242     DECLARE_DYNAMIC_CLASS(wxPackageRepositoryXMLDescriptor)
00243 
00244 public:
00245     wxPackageRepositoryXMLDescriptor() {}
00246     virtual ~wxPackageRepositoryXMLDescriptor() {}
00247 
00248     // loads the given gzipped WXL file:
00249     bool Load(const wxString &filename);
00250 
00251     // loads the WXL from the given input stream (which is supposed decompressed):
00252     bool Load(wxInputStream &stream)
00253         { return wxPackageXML::Load(stream); }
00254 
00255 public:     // setters
00256 
00257     bool AddPackage(const wxString &pkgfile);
00258 
00259 public:     // getters
00260 
00264     wxPackageArray GetPackageArray(const wxString &repourl);
00265 };
00266 
00267 
00268 #endif      // _WXP_H_
00269 

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