Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
12f6058d
Commit
12f6058d
authored
Jan 07, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил пару вспомогательных функций "для удобства инициализации".
(getProp2(),getArg2Param())
parent
07661f58
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
0 deletions
+36
-0
Configuration.h
include/Configuration.h
+2
-0
UniXML.h
include/UniXML.h
+3
-0
Configuration.cc
src/Various/Configuration.cc
+12
-0
UniXML.cc
src/Various/UniXML.cc
+14
-0
test_unixml.cc
tests/test_unixml.cc
+5
-0
No files found.
include/Configuration.h
View file @
12f6058d
...
...
@@ -133,6 +133,8 @@ namespace UniSetTypes
/*! получить значение указанного параметра, или значение по умолчанию */
std
::
string
getArgParam
(
const
std
::
string
&
name
,
const
std
::
string
&
defval
=
""
);
/*! получить значение, если пустое, то defval, если defval="" return defval2 */
std
::
string
getArg2Param
(
const
std
::
string
&
name
,
const
std
::
string
&
defval
,
const
std
::
string
&
defval2
=
""
);
/*! получить числовое значение параметра, если не число, то 0. Если параметра нет, используется значение defval */
int
getArgInt
(
const
std
::
string
&
name
,
const
std
::
string
&
defval
=
""
);
/*! получить числовое значение параметра, но если оно не положительное, вернуть defval */
...
...
include/UniXML.h
View file @
12f6058d
...
...
@@ -46,6 +46,7 @@ class UniXML_iterator:
{}
UniXML_iterator
()
{}
std
::
string
getProp2
(
const
std
::
string
&
name
,
const
std
::
string
&
defval
=
""
);
std
::
string
getProp
(
const
std
::
string
&
name
);
std
::
string
getPropUtf8
(
const
std
::
string
&
name
);
int
getIntProp
(
const
std
::
string
&
name
);
...
...
@@ -195,6 +196,8 @@ public:
// Получить свойство name указанного узла node
static
std
::
string
getProp
(
const
xmlNode
*
node
,
const
std
::
string
&
name
);
static
std
::
string
getProp2
(
const
xmlNode
*
node
,
const
std
::
string
&
name
,
const
std
::
string
&
defval
=
""
);
static
std
::
string
getPropUtf8
(
const
xmlNode
*
node
,
const
std
::
string
&
name
);
static
int
getIntProp
(
const
xmlNode
*
node
,
const
std
::
string
&
name
);
/// if value if not positive ( <= 0 ), returns def
...
...
src/Various/Configuration.cc
View file @
12f6058d
...
...
@@ -400,6 +400,18 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
}
// -------------------------------------------------------------------------
std
::
string
Configuration
::
getArg2Param
(
const
std
::
string
&
name
,
const
std
::
string
&
defval
,
const
std
::
string
&
defval2
)
{
string
s
(
UniSetTypes
::
getArgParam
(
name
,
_argc
,
_argv
,
""
));
if
(
!
s
.
empty
()
)
return
std
::
move
(
s
);
if
(
!
defval
.
empty
()
)
return
defval
;
return
defval2
;
}
string
Configuration
::
getArgParam
(
const
string
&
name
,
const
string
&
defval
)
{
return
UniSetTypes
::
getArgParam
(
name
,
_argc
,
_argv
,
defval
);
...
...
src/Various/UniXML.cc
View file @
12f6058d
...
...
@@ -116,6 +116,15 @@ string UniXML::getPropUtf8(const xmlNode* node, const string& name)
return
getProp
(
node
,
name
);
}
string
UniXML
::
getProp2
(
const
xmlNode
*
node
,
const
string
&
name
,
const
string
&
defval
)
{
string
s
(
getProp
(
node
,
name
));
if
(
!
s
.
empty
()
)
return
std
::
move
(
s
);
return
defval
;
}
string
UniXML
::
getProp
(
const
xmlNode
*
node
,
const
string
&
name
)
{
xmlChar
*
text
=
::
xmlGetProp
((
xmlNode
*
)
node
,
(
const
xmlChar
*
)
name
.
c_str
());
...
...
@@ -386,6 +395,11 @@ bool UniXML_iterator::goChildren()
}
// -------------------------------------------------------------------------
string
UniXML_iterator
::
getProp2
(
const
string
&
name
,
const
string
&
defval
)
{
return
UniXML
::
getProp2
(
curNode
,
name
,
defval
);
}
string
UniXML_iterator
::
getProp
(
const
string
&
name
)
{
return
UniXML
::
getProp
(
curNode
,
name
);
...
...
tests/test_unixml.cc
View file @
12f6058d
...
...
@@ -39,6 +39,9 @@ TEST_CASE("UniXML", "[unixml][basic]" )
CHECK
(
uxml
.
getPIntProp
(
tnode
,
"negative"
,
20
)
==
-
10
);
CHECK
(
uxml
.
getPIntProp
(
tnode
,
"unknown"
,
20
)
==
20
);
CHECK
(
uxml
.
getProp2
(
tnode
,
"unknown"
,
"def"
)
==
"def"
);
CHECK
(
uxml
.
getProp2
(
tnode
,
"text"
,
"def"
)
==
"text"
);
// nextNode
// create
// remove
...
...
@@ -114,6 +117,8 @@ TEST_CASE("UniXML::iterator", "[unixml][iterator][basic]" )
CHECK
(
it
.
find
(
"TestData"
)
!=
0
);
CHECK
(
it
.
getProp
(
"text"
)
==
"text"
);
CHECK
(
it
.
getProp2
(
"text"
,
"def"
)
==
"text"
);
CHECK
(
it
.
getProp2
(
"unknown"
,
"def"
)
==
"def"
);
CHECK
(
it
.
getIntProp
(
"x"
)
==
10
);
CHECK
(
it
.
getPIntProp
(
"y"
,
-
20
)
==
100
);
CHECK
(
it
.
getPIntProp
(
"zero"
,
20
)
==
0
);
...
...
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