Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
fd754ff8
Commit
fd754ff8
authored
Jan 22, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Directory: replace std::vector with a simple enum
Reduce bloat.
parent
b7738e7a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
20 deletions
+34
-20
Directory.cxx
src/db/upnp/Directory.cxx
+34
-20
No files found.
src/db/upnp/Directory.cxx
View file @
fd754ff8
...
@@ -28,17 +28,26 @@
...
@@ -28,17 +28,26 @@
#include <algorithm>
#include <algorithm>
#include <string>
#include <string>
#include <vector>
#include <string.h>
#include <string.h>
gcc_pure
gcc_nonnull_all
static
bool
CompareStringLiteral
(
const
char
*
literal
,
const
char
*
value
,
size_t
length
)
{
return
length
==
strlen
(
literal
)
&&
memcmp
(
literal
,
value
,
length
)
==
0
;
}
gcc_pure
gcc_pure
static
UPnPDirObject
::
ItemClass
static
UPnPDirObject
::
ItemClass
ParseItemClass
(
const
char
*
name
)
ParseItemClass
(
const
char
*
name
,
size_t
length
)
{
{
if
(
strcmp
(
name
,
"object.item.audioItem.musicTrack"
)
==
0
)
if
(
CompareStringLiteral
(
"object.item.audioItem.musicTrack"
,
name
,
length
))
return
UPnPDirObject
::
ItemClass
::
MUSIC
;
return
UPnPDirObject
::
ItemClass
::
MUSIC
;
else
if
(
strcmp
(
name
,
"object.item.playlistItem"
)
==
0
)
else
if
(
CompareStringLiteral
(
"object.item.playlistItem"
,
name
,
length
))
return
UPnPDirObject
::
ItemClass
::
PLAYLIST
;
return
UPnPDirObject
::
ItemClass
::
PLAYLIST
;
else
else
return
UPnPDirObject
::
ItemClass
::
UNKNOWN
;
return
UPnPDirObject
::
ItemClass
::
UNKNOWN
;
...
@@ -88,7 +97,11 @@ titleToPathElt(std::string &&s)
...
@@ -88,7 +97,11 @@ titleToPathElt(std::string &&s)
class
UPnPDirParser
final
:
public
CommonExpatParser
{
class
UPnPDirParser
final
:
public
CommonExpatParser
{
UPnPDirContent
&
m_dir
;
UPnPDirContent
&
m_dir
;
std
::
vector
<
std
::
string
>
m_path
;
enum
{
NONE
,
RES
,
CLASS
,
}
state
;
/**
/**
* If not equal to #TAG_NUM_OF_ITEM_TYPES, then we're
* If not equal to #TAG_NUM_OF_ITEM_TYPES, then we're
...
@@ -108,6 +121,7 @@ class UPnPDirParser final : public CommonExpatParser {
...
@@ -108,6 +121,7 @@ class UPnPDirParser final : public CommonExpatParser {
public
:
public
:
UPnPDirParser
(
UPnPDirContent
&
dir
)
UPnPDirParser
(
UPnPDirContent
&
dir
)
:
m_dir
(
dir
),
:
m_dir
(
dir
),
state
(
NONE
),
tag_type
(
TAG_NUM_OF_ITEM_TYPES
)
tag_type
(
TAG_NUM_OF_ITEM_TYPES
)
{
{
}
}
...
@@ -115,8 +129,6 @@ public:
...
@@ -115,8 +129,6 @@ public:
protected
:
protected
:
virtual
void
StartElement
(
const
XML_Char
*
name
,
const
XML_Char
**
attrs
)
virtual
void
StartElement
(
const
XML_Char
*
name
,
const
XML_Char
**
attrs
)
{
{
m_path
.
push_back
(
name
);
if
(
m_tobj
.
type
!=
UPnPDirObject
::
Type
::
UNKNOWN
&&
if
(
m_tobj
.
type
!=
UPnPDirObject
::
Type
::
UNKNOWN
&&
tag_type
==
TAG_NUM_OF_ITEM_TYPES
)
{
tag_type
==
TAG_NUM_OF_ITEM_TYPES
)
{
tag_type
=
tag_table_lookup
(
upnp_tags
,
name
);
tag_type
=
tag_table_lookup
(
upnp_tags
,
name
);
...
@@ -167,9 +179,15 @@ protected:
...
@@ -167,9 +179,15 @@ protected:
GetAttribute
(
attrs
,
"duration"
);
GetAttribute
(
attrs
,
"duration"
);
if
(
duration
!=
nullptr
)
if
(
duration
!=
nullptr
)
tag
.
SetTime
(
ParseDuration
(
duration
));
tag
.
SetTime
(
ParseDuration
(
duration
));
state
=
RES
;
}
}
break
;
break
;
case
'u'
:
if
(
strcmp
(
name
,
"upnp:class"
)
==
0
)
state
=
CLASS
;
}
}
}
}
...
@@ -204,7 +222,7 @@ protected:
...
@@ -204,7 +222,7 @@ protected:
m_dir
.
objects
.
push_back
(
std
::
move
(
m_tobj
));
m_dir
.
objects
.
push_back
(
std
::
move
(
m_tobj
));
}
}
m_path
.
pop_back
()
;
state
=
NONE
;
}
}
virtual
void
CharacterData
(
const
XML_Char
*
s
,
int
len
)
virtual
void
CharacterData
(
const
XML_Char
*
s
,
int
len
)
...
@@ -216,20 +234,16 @@ protected:
...
@@ -216,20 +234,16 @@ protected:
return
;
return
;
}
}
const
auto
&
current
=
m_path
.
back
();
switch
(
state
)
{
std
::
string
str
=
trimstring
(
s
,
len
);
case
NONE
:
break
;
switch
(
current
[
0
])
{
case
RES
:
case
'r'
:
m_tobj
.
url
.
assign
(
s
,
len
);
if
(
!
current
.
compare
(
"res"
))
{
m_tobj
.
url
=
std
::
move
(
str
);
}
break
;
break
;
case
'u'
:
if
(
current
==
"upnp:class"
)
{
case
CLASS
:
m_tobj
.
item_class
=
ParseItemClass
(
str
.
c_str
());
m_tobj
.
item_class
=
ParseItemClass
(
s
,
len
);
break
;
}
break
;
break
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment