Audacity  3.0.3
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
UpdateDataParser Class Referencefinal

A class that parses update server data format. More...

#include <UpdateDataParser.h>

Inheritance diagram for UpdateDataParser:
[legend]
Collaboration diagram for UpdateDataParser:
[legend]

Public Member Functions

 UpdateDataParser ()
 
 ~UpdateDataParser ()
 
bool Parse (const VersionPatch::UpdateDataFormat &updateData, VersionPatch *versionPatch)
 Parsing from update data format to VersionPatch fields. More...
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Private Types

enum  XmlParsedTags : int {
  XmlParsedTags::kNotUsedTag, XmlParsedTags::kUpdateTag, XmlParsedTags::kDescriptionTag, XmlParsedTags::kOsTag,
  XmlParsedTags::kWin32Tag, XmlParsedTags::kWin64Tag, XmlParsedTags::kMacosTag, XmlParsedTags::kLinuxTag,
  XmlParsedTags::kVersionTag, XmlParsedTags::kLinkTag
}
 

Private Member Functions

bool HandleXMLTag (const wxChar *tag, const wxChar **attrs) override
 
void HandleXMLEndTag (const wxChar *tag) override
 
void HandleXMLContent (const wxString &content) override
 
XMLTagHandlerHandleXMLChild (const wxChar *tag) override
 
wxArrayString SplitChangelogSentences (const wxString &changelogContent)
 

Private Attributes

XmlParsedTags mXmlParsingState { XmlParsedTags::kNotUsedTag }
 
std::map< XmlParsedTags, wxString > mXmlTagNames
 
VersionPatchmVersionPatch { nullptr }
 

Detailed Description

A class that parses update server data format.

Definition at line 19 of file UpdateDataParser.h.

Member Enumeration Documentation

◆ XmlParsedTags

enum UpdateDataParser::XmlParsedTags : int
strongprivate
Enumerator
kNotUsedTag 
kUpdateTag 
kDescriptionTag 
kOsTag 
kWin32Tag 
kWin64Tag 
kMacosTag 
kLinuxTag 
kVersionTag 
kLinkTag 

Definition at line 34 of file UpdateDataParser.h.

34  : int {
35  kNotUsedTag,
36  kUpdateTag,
37  kDescriptionTag,
38  kOsTag,
39  kWin32Tag,
40  kWin64Tag,
41  kMacosTag,
42  kLinuxTag,
43  kVersionTag,
44  kLinkTag
45  };

Constructor & Destructor Documentation

◆ UpdateDataParser()

UpdateDataParser::UpdateDataParser ( )

Definition at line 16 of file UpdateDataParser.cpp.

17 {}

◆ ~UpdateDataParser()

UpdateDataParser::~UpdateDataParser ( )

Definition at line 19 of file UpdateDataParser.cpp.

20 {}

Member Function Documentation

◆ HandleXMLChild()

XMLTagHandler * UpdateDataParser::HandleXMLChild ( const wxChar *  tag)
overrideprivatevirtual

Implements XMLTagHandler.

Definition at line 163 of file UpdateDataParser.cpp.

164 {
165  for (auto& xmlTag : mXmlTagNames)
166  {
167  if (wxStrcmp(tag, xmlTag.second) == 0)
168  return this;
169  }
170 
171  return NULL;
172 }

References mXmlTagNames.

◆ HandleXMLContent()

void UpdateDataParser::HandleXMLContent ( const wxString &  content)
overrideprivate

Definition at line 134 of file UpdateDataParser.cpp.

135 {
136  if (mVersionPatch == nullptr)
137  return;
138 
139  wxString trimmedContent(content);
140 
141  switch (mXmlParsingState)
142  {
144  trimmedContent.Trim(true).Trim(false);
146  break;
147 
149  trimmedContent.Trim(true).Trim(false);
151  break;
152 
154  trimmedContent.Trim(true).Trim(false);
155  mVersionPatch->download = trimmedContent;
156  break;
157 
158  default:
159  break;
160  }
161 }

References VersionPatch::changelog, VersionPatch::download, kDescriptionTag, kLinkTag, kVersionTag, mVersionPatch, mXmlParsingState, VersionId::ParseFromString(), SplitChangelogSentences(), and VersionPatch::version.

Here is the call graph for this function:

◆ HandleXMLEndTag()

void UpdateDataParser::HandleXMLEndTag ( const wxChar *  tag)
overrideprivate

Definition at line 122 of file UpdateDataParser.cpp.

123 {
127 
128  // If it is our working OS, using "kOsTag" for keeping ready for parse state for both tags:
129  // <Version> and <Link>, that ordered one after another.
132 }

References kDescriptionTag, kLinkTag, kNotUsedTag, kOsTag, kVersionTag, and mXmlParsingState.

◆ HandleXMLTag()

bool UpdateDataParser::HandleXMLTag ( const wxChar *  tag,
const wxChar **  attrs 
)
overrideprivatevirtual

Implements XMLTagHandler.

Definition at line 52 of file UpdateDataParser.cpp.

53 {
54  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kDescriptionTag]) == 0)
55  {
57  return true;
58  }
59 
60  const wxPlatformInfo& info = wxPlatformInfo::Get();
61 
62  constexpr bool is32Bit = sizeof(void*) == 4;
63  constexpr bool is64Bit = sizeof(void*) == 8;
64 
65  if (is32Bit)
66  {
67  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kWin32Tag]) == 0)
68  {
69  if (info.GetOperatingSystemId() & wxOS_WINDOWS)
71  return true;
72  }
73  }
74 
75  if (is64Bit)
76  {
77  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kWin64Tag]) == 0)
78  {
79  if (info.GetOperatingSystemId() & wxOS_WINDOWS)
81  return true;
82  }
83  }
84 
85  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kMacosTag]) == 0)
86  {
87  if (info.GetOperatingSystemId() & wxOS_MAC)
89  return true;
90  }
91 
92  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kLinuxTag]) == 0)
93  {
94  if (info.GetOperatingSystemId() & wxOS_UNIX_LINUX)
96  return true;
97  }
98 
99  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kVersionTag]) == 0)
100  {
103  return true;
104  }
105 
106  if (wxStrcmp(tag, mXmlTagNames[XmlParsedTags::kLinkTag]) == 0)
107  {
110  return true;
111  }
112 
113  for (auto& xmlTag : mXmlTagNames)
114  {
115  if (wxStrcmp(tag, xmlTag.second) == 0)
116  return true;
117  }
118 
119  return false;
120 }

References BasicUI::Get(), kDescriptionTag, kLinkTag, kLinuxTag, kMacosTag, kOsTag, kVersionTag, kWin32Tag, kWin64Tag, mXmlParsingState, and mXmlTagNames.

Here is the call graph for this function:

◆ Parse()

bool UpdateDataParser::Parse ( const VersionPatch::UpdateDataFormat updateData,
VersionPatch versionPatch 
)

Parsing from update data format to VersionPatch fields.

Parameters
updateDataInputData.
versionPathParsed output data.
Returns
True if success.

Definition at line 22 of file UpdateDataParser.cpp.

23 {
24  XMLFileReader xmlReader;
25 
26  ValueRestorer<VersionPatch*> setter{ mVersionPatch, versionPatch };
27 
28  return xmlReader.ParseString(this, updateData);
29 }

References mVersionPatch, and XMLFileReader::ParseString().

Referenced by UpdateManager::GetUpdates().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SplitChangelogSentences()

wxArrayString UpdateDataParser::SplitChangelogSentences ( const wxString &  changelogContent)
private

Definition at line 31 of file UpdateDataParser.cpp.

32 {
33  wxArrayString changelogSentenceList;
34 
35  size_t pos = 0;
36  std::string s(changelogContent.ToStdString());
37  std::string token;
38  const std::string delimiter(". ");
39 
40  while ((pos = s.find(delimiter)) != std::string::npos)
41  {
42  token = s.substr(0, pos + 1);
43  changelogSentenceList.Add(wxString(token).Trim());
44 
45  s.erase(0, pos + delimiter.length());
46  }
47  changelogSentenceList.Add(wxString(s).Trim());
48 
49  return changelogSentenceList;
50 }

Referenced by HandleXMLContent().

Here is the caller graph for this function:

Member Data Documentation

◆ mVersionPatch

VersionPatch* UpdateDataParser::mVersionPatch { nullptr }
private

Definition at line 67 of file UpdateDataParser.h.

Referenced by HandleXMLContent(), and Parse().

◆ mXmlParsingState

XmlParsedTags UpdateDataParser::mXmlParsingState { XmlParsedTags::kNotUsedTag }
private

Definition at line 46 of file UpdateDataParser.h.

Referenced by HandleXMLContent(), HandleXMLEndTag(), and HandleXMLTag().

◆ mXmlTagNames

std::map<XmlParsedTags, wxString> UpdateDataParser::mXmlTagNames
private
Initial value:
{
{ XmlParsedTags::kUpdateTag, wxT("Updates") },
{ XmlParsedTags::kDescriptionTag, wxT("Description") },
{ XmlParsedTags::kOsTag, wxT("OS") },
{ XmlParsedTags::kWin32Tag, wxT("Win32") },
{ XmlParsedTags::kWin64Tag, wxT("Win64") },
{ XmlParsedTags::kMacosTag, wxT("Macos") },
{ XmlParsedTags::kLinuxTag, wxT("Linux") },
{ XmlParsedTags::kVersionTag, wxT("Version") },
{ XmlParsedTags::kLinkTag, wxT("Link") },
}

Definition at line 48 of file UpdateDataParser.h.

Referenced by HandleXMLChild(), and HandleXMLTag().


The documentation for this class was generated from the following files:
UpdateDataParser::SplitChangelogSentences
wxArrayString SplitChangelogSentences(const wxString &changelogContent)
Definition: UpdateDataParser.cpp:31
VersionPatch::version
VersionId version
Definition: VersionPatch.h:20
VersionPatch::changelog
wxArrayString changelog
Definition: VersionPatch.h:21
UpdateDataParser::XmlParsedTags::kLinuxTag
@ kLinuxTag
UpdateDataParser::mVersionPatch
VersionPatch * mVersionPatch
Definition: UpdateDataParser.h:67
UpdateDataParser::XmlParsedTags::kWin32Tag
@ kWin32Tag
UpdateDataParser::mXmlParsingState
XmlParsedTags mXmlParsingState
Definition: UpdateDataParser.h:46
VersionId::ParseFromString
static VersionId ParseFromString(wxString &versionString)
Parse and return version object from version string like "1.2.3".
Definition: VersionId.cpp:24
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
XMLFileReader::ParseString
bool ParseString(XMLTagHandler *baseHandler, const wxString &xmldata)
Definition: XMLFileReader.cpp:136
UpdateDataParser::XmlParsedTags::kNotUsedTag
@ kNotUsedTag
UpdateDataParser::XmlParsedTags::kDescriptionTag
@ kDescriptionTag
UpdateDataParser::XmlParsedTags::kVersionTag
@ kVersionTag
VersionPatch::download
wxString download
Definition: VersionPatch.h:22
UpdateDataParser::XmlParsedTags::kMacosTag
@ kMacosTag
XMLFileReader
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:18
UpdateDataParser::XmlParsedTags::kOsTag
@ kOsTag
ValueRestorer
Set a variable temporarily in a scope.
Definition: MemoryX.h:332
UpdateDataParser::XmlParsedTags::kUpdateTag
@ kUpdateTag
UpdateDataParser::XmlParsedTags::kLinkTag
@ kLinkTag
UpdateDataParser::XmlParsedTags::kWin64Tag
@ kWin64Tag
UpdateDataParser::mXmlTagNames
std::map< XmlParsedTags, wxString > mXmlTagNames
Definition: UpdateDataParser.h:48