00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifndef _PACKAGEUTILS_H_
00014 #define _PACKAGEUTILS_H_
00015
00016
00017 #include "wx/string.h"
00018 #include "wx/log.h"
00019 #include "wx/platinfo.h"
00020
00021 #include "wxp/version.h"
00022 #include "wxp/compiler.h"
00023
00024 class wxPackage;
00025 class wxPackageDataWithRef;
00026 class wxPackageId;
00027 class wxPackageIdArray;
00028 class wxPackageCondition;
00029 class wxPackageHTMLOutputFormat;
00030
00031 extern wxPackageDataWithRef wxEmptyPackageDataWithRef;
00032 extern wxPackageId wxEmptyPackageId;
00033 extern wxPackageIdArray wxEmptyPackageIdArray;
00034 extern wxPackageCondition wxEmptyPackageCondition;
00035 extern wxPackageHTMLOutputFormat wxEmptyPackageHTMLOutputFormat;
00036
00037
00038
00039
00040
00041
00043 enum wxPackageSubstituteInfoContext
00044 {
00045 wxPSIC_INVALID = -1,
00046
00047 wxPSIC_WXHTML,
00048 wxPSIC_XHTML,
00049
00050 wxPSIC_MAX
00051 };
00052
00053 wxDEFINE_STRING2ENUM(PackageSubstituteInfoContext)
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class wxPackageDataWithRef : public wxObject
00065 {
00066 public:
00067 wxPackageDataWithRef(
00068 const wxString &data = wxEmptyString,
00069 const wxString &href = wxEmptyString,
00070 const wxString &localref = wxEmptyString)
00071 : m_strData(data), m_strHref(href), m_strLocalRef(localref) {}
00072
00073 public:
00074
00075 wxString GetData() const
00076 { return m_strData; }
00077 wxString GetHref() const
00078 { return m_strHref; }
00079 wxString GetLocalRef() const
00080 { return m_strLocalRef; }
00081
00083 wxString GetBestRef() const
00084 {
00085 if (m_strLocalRef.StartsWith(wxT("file:")) ||
00086 wxFileExists(m_strLocalRef))
00087 return m_strLocalRef;
00088 return m_strHref;
00089 }
00090
00091 public:
00092
00093 void SetData(const wxString &data)
00094 { m_strData=data; }
00095 void SetHref(const wxString &data)
00096 { m_strHref=data; }
00097 void SetLocalRef(const wxString &data)
00098 { m_strLocalRef=data; }
00099
00100 public:
00101
00103 void ExpandLocalRef(const wxString &path);
00104
00109 void ExpandLocalRefToWXZRef(const wxString &wxzpath);
00110
00113 void RemoveLocalRef()
00114 { m_strLocalRef.Empty(); }
00115
00116 protected:
00117 wxString m_strData, m_strHref, m_strLocalRef;
00118 };
00119
00120
00121 WX_DECLARE_OBJARRAY(wxPackageDataWithRef, wxPackageDataWithRefArray);
00122
00123
00124
00125
00126
00127
00128
00131 class wxPackageId : public wxObject
00132 {
00133 public:
00134 wxPackageId(const wxString &name = wxEmptyString,
00135 const wxVersion &ver = wxEmptyVersion)
00136 : m_strName(name), m_version(ver) {}
00137 virtual ~wxPackageId() {}
00138
00139 public:
00140
00141 bool operator== (const wxPackageId &i) const
00142 { return m_strName.CmpNoCase(i.m_strName) == 0 && m_version==i.m_version; }
00143 bool operator!= (const wxPackageId &i) const
00144 { return !(*this == i); }
00145
00146 public:
00147
00148 wxString GetName() const { return m_strName; }
00149 wxVersion GetVersion() const { return m_version; }
00150
00151 public:
00152
00153 void SetName(const wxString &name)
00154 { m_strName=name; }
00155 void SetVersion(const wxVersion &ver)
00156 { m_version=ver; }
00157
00158 bool IsOk() const
00159 {
00160 return !m_strName.IsEmpty() && !m_strName.Contains(wxT(' ')) &&
00161 m_version.IsOk();
00162 }
00163
00164 protected:
00165 wxString m_strName;
00166 wxVersion m_version;
00167 };
00168
00169
00170 WX_DECLARE_OBJARRAY(wxPackageId, wxPackageIdArrayHelper);
00171
00172
00173
00174
00175
00176
00177
00178 class wxPackageIdArray : public wxPackageIdArrayHelper
00179 {
00180 public:
00181
00183 wxPackageIdArray() {}
00184
00185 public:
00186
00188 bool IsOk() const
00189 {
00190 for (size_t i=0; i<GetCount(); i++)
00191 if (!Item(i).IsOk())
00192 return false;
00193 return true;
00194 }
00195
00196 int Index(const wxPackageId &p) const
00197 {
00198 for (size_t i=0; i<GetCount(); i++)
00199 if (Item(i) == p)
00200 return i;
00201 return wxNOT_FOUND;
00202 }
00203
00204 void Dump()
00205 {
00206 for (size_t i=0; i<GetCount(); i++)
00207 wxLogDebug(wxT("%s %s"), Item(i).GetName().c_str(),
00208 Item(i).GetVersion().GetAsString().c_str());
00209 }
00210 };
00211
00212
00213
00214
00215
00216
00217
00221 class wxPackageCondition : public wxObject
00222 {
00223 DECLARE_DYNAMIC_CLASS(wxPackageCondition)
00224
00225 public:
00226 wxPackageCondition(long plat = 0,
00227 long formats = 0,
00228 long buildsys = 0,
00229 long stages = 0)
00230 {
00231 SetFormats(formats);
00232 SetPlatforms(plat);
00233 SetBuildSystems(buildsys);
00234 SetStages(stages);
00235 }
00236 virtual ~wxPackageCondition() {}
00237
00238
00239 bool operator==(const wxPackageCondition &cond) const;
00240 bool operator!=(const wxPackageCondition &cond) const
00241 { return !(*this == cond); }
00242
00243 public:
00244
00245 long GetFormats() const
00246 { return m_format; }
00247 long GetPlatforms() const
00248 { return m_platform; }
00249 long GetBuildSystems() const
00250 { return m_buildSys; }
00251 long GetStages() const
00252 { return m_stages; }
00253
00254
00255 static long GetCurrentPlatform()
00256 { return wxPlatformInfo::Get().GetPortId(); }
00257
00258 public:
00259
00260 wxString GetFormatsStr() const
00261 { return wxPackageCompilerFormatList2String(m_format); }
00262 wxString GetBuildSystemsStr() const
00263 { return wxPackageBuildSystemTypeList2String(m_buildSys); }
00264 wxString GetStagesStr() const
00265 { return wxPackageBuildSystemStageList2String(m_stages); }
00266 wxString GetPlatformsStr() const
00267 {
00268 wxString ret;
00269 for (size_t i=0; i < wxPORT_MAX; i++)
00270 {
00271 wxPortId cur = (wxPortId)(1 << i);
00272 if ((m_platform & cur) != 0)
00273 ret += wxPlatformInfo::GetPortIdName(cur, false) + wxT(",");
00274 }
00275
00276 if (ret.EndsWith(wxT(",")))
00277 ret.RemoveLast();
00278 return ret;
00279 }
00280
00281 public:
00282
00283 void SetFormats(long fmt)
00284 { m_format=fmt; }
00285 void SetPlatforms(long plat)
00286 { m_platform=plat; }
00287 void SetBuildSystems(long build)
00288 { m_buildSys=build; }
00289 void SetStages(long stages)
00290 { m_stages=stages; }
00291
00292 public:
00293
00295 bool IsValidForCurrentPlatform() const
00296 { return (m_platform & GetCurrentPlatform()) != 0; }
00297
00299 bool IsValidForCompiler(wxPackageCompilerFormat fmt) const
00300 { return (m_format & fmt) != 0; }
00301
00303 bool IsValidForBuildSys(wxPackageBuildSystemType fmt) const
00304 { return (m_buildSys & fmt) != 0; }
00305
00307 bool IsValidForStage(wxPackageBuildSystemStage stage) const
00308 { return (m_stages & stage) != 0; }
00309
00312 bool IsValidForStages(long stages) const
00313 { return (m_stages & stages) != 0; }
00314
00317 bool IsValidForCompilers(long fmt) const
00318 { return (m_format & fmt) != 0; }
00319
00322 bool IsValidForPackage(const wxPackage &pkg) const;
00323
00325 void SetAlwaysTrue();
00326
00328 bool IsAlwaysTrue() const
00329 {
00330
00331 return m_platform == wxGetFullPortIdList() &&
00332 m_format == wxGetFullPackageCompilerFormatList() &&
00333 m_buildSys == wxGetFullPackageBuildSystemTypeList() &&
00334 m_stages == wxGetFullPackageBuildSystemStageList();
00335 }
00336
00338 bool IsAlwaysFalse() const
00339 {
00340 return m_platform == 0 &&
00341 m_format == 0 &&
00342 m_buildSys == 0 &&
00343 m_stages == 0;
00344 }
00345
00348 bool Matches(const wxPackageCondition &cond) const
00349 {
00350 return (m_format & cond.m_format) != 0 &&
00351 (m_platform & cond.m_platform) != 0 &&
00352 (m_buildSys & cond.m_buildSys) != 0 &&
00353 (m_stages & cond.m_stages) != 0;
00354 }
00355
00361 void IntersecateWith(const wxPackageCondition &cond)
00362 {
00363 m_format &= cond.m_format;
00364 m_platform &= cond.m_platform;
00365 m_buildSys &= cond.m_buildSys;
00366 m_stages &= cond.m_stages;
00367 }
00368
00369
00370 bool IsOk() const
00371 { return !IsAlwaysFalse(); }
00372
00373 protected:
00374
00379 long m_platform;
00380
00384 long m_format;
00385
00389 long m_buildSys;
00390
00394 long m_stages;
00395 };
00396
00397
00398
00399
00400
00401
00402
00405 class wxPackageHTMLOutputFormat
00406 {
00407 friend class wxPackageHTMLOutputFormatXMLDescriptor;
00408
00409 public:
00410 wxPackageHTMLOutputFormat(const wxString &name = wxEmptyString,
00411 const wxString &desc = wxEmptyString,
00412 const wxString &summary = wxEmptyString,
00413 const wxString &details = wxEmptyString,
00414 wxPackageSubstituteInfoContext ctx = wxPSIC_INVALID)
00415 {
00416 m_strName=name;
00417 m_strDescription=desc;
00418 m_strSummary=summary;
00419 m_strDetails=details;
00420 m_ctx=ctx;
00421 }
00422
00423 bool operator == (const wxPackageHTMLOutputFormat &fmt) const
00424 {
00425 return m_strSummary == fmt.m_strSummary &&
00426 m_strDetails == fmt.m_strDetails &&
00427 m_strName == fmt.m_strName &&
00428 m_strDescription == fmt.m_strDescription &&
00429 m_ctx == fmt.m_ctx;
00430 }
00431
00432 bool operator != (const wxPackageHTMLOutputFormat &fmt) const
00433 { return !(*this == fmt); }
00434
00435 public:
00436
00437 wxString GetName() const
00438 { return m_strName; }
00439 wxString GetDescription() const
00440 { return m_strDescription; }
00441
00442 wxString GetSummary() const
00443 { return m_strSummary; }
00444 wxString GetDetails() const
00445 { return m_strDetails; }
00446
00447 wxPackageSubstituteInfoContext GetContext() const
00448 { return m_ctx; }
00449 wxString GetContextStr() const
00450 { return wxPackageSubstituteInfoContext2String(m_ctx); }
00451
00452 wxString GetSummaryFor(const wxPackageInfo &pkg) const;
00453 wxString GetDetailsFor(const wxPackageInfo &pkg) const;
00454
00455 public:
00456
00457 bool IsOk() const
00458 {
00459 return !m_strSummary.IsEmpty() &&
00460 !m_strDetails.IsEmpty();
00461 }
00462
00463 bool Load(const wxString &dirname);
00464
00465 protected:
00466
00467
00468 wxString m_strName, m_strDescription;
00469 wxPackageSubstituteInfoContext m_ctx;
00470
00471
00472 wxString m_strSummary, m_strDetails;
00473 };
00474
00475
00476 WX_DECLARE_STRING_HASH_MAP( wxPackageHTMLOutputFormat,
00477 wxPackageHTMLOutputFormatHashMap );
00478
00479
00480 #endif // _PACKAGEUTILS_H_
00481