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
d5656600
Commit
d5656600
authored
Dec 15, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(UniXML): добавил функцию getPropList().
parent
23520fb8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
0 deletions
+65
-0
UniXML.h
include/UniXML.h
+7
-0
UniXML.cc
src/Various/UniXML.cc
+25
-0
test_unixml.cc
tests/test_unixml.cc
+30
-0
tests_unixml.xml
tests/tests_unixml.xml
+2
-0
uniset2.includes
uniset2.includes
+1
-0
No files found.
include/UniXML.h
View file @
d5656600
...
@@ -31,12 +31,14 @@
...
@@ -31,12 +31,14 @@
#include <string>
#include <string>
#include <cstddef>
#include <cstddef>
#include <memory>
#include <memory>
#include <vector>
#include <libxml/parser.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/tree.h>
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
namespace
uniset
namespace
uniset
{
{
typedef
std
::
vector
<
std
::
pair
<
const
std
::
string
,
const
std
::
string
>
>
UniXMLPropList
;
class
UniXML_iterator
:
class
UniXML_iterator
:
public
std
::
iterator
<
std
::
bidirectional_iterator_tag
,
xmlNode
,
ptrdiff_t
,
xmlNode
*
,
xmlNode
&>
public
std
::
iterator
<
std
::
bidirectional_iterator_tag
,
xmlNode
,
ptrdiff_t
,
xmlNode
*
,
xmlNode
&>
...
@@ -104,6 +106,8 @@ namespace uniset
...
@@ -104,6 +106,8 @@ namespace uniset
void
goBegin
()
noexcept
;
void
goBegin
()
noexcept
;
void
goEnd
()
noexcept
;
void
goEnd
()
noexcept
;
UniXMLPropList
getPropList
()
const
;
private
:
private
:
xmlNode
*
curNode
;
xmlNode
*
curNode
;
...
@@ -114,6 +118,7 @@ namespace uniset
...
@@ -114,6 +118,7 @@ namespace uniset
public
:
public
:
typedef
UniXML_iterator
iterator
;
typedef
UniXML_iterator
iterator
;
typedef
UniXMLPropList
PropList
;
UniXML
(
const
std
::
string
&
filename
);
UniXML
(
const
std
::
string
&
filename
);
UniXML
();
UniXML
();
...
@@ -149,6 +154,8 @@ namespace uniset
...
@@ -149,6 +154,8 @@ namespace uniset
// Установить свойство name указанного узла node
// Установить свойство name указанного узла node
static
void
setProp
(
xmlNode
*
node
,
const
std
::
string
&
name
,
const
std
::
string
&
text
);
static
void
setProp
(
xmlNode
*
node
,
const
std
::
string
&
name
,
const
std
::
string
&
text
);
static
UniXMLPropList
getPropList
(
xmlNode
*
node
);
// Добавить новый дочерний узел
// Добавить новый дочерний узел
static
xmlNode
*
createChild
(
xmlNode
*
node
,
const
std
::
string
&
title
,
const
std
::
string
&
text
);
static
xmlNode
*
createChild
(
xmlNode
*
node
,
const
std
::
string
&
title
,
const
std
::
string
&
text
);
...
...
src/Various/UniXML.cc
View file @
d5656600
...
@@ -210,6 +210,26 @@ void UniXML::setProp(xmlNode* node, const string& name, const string& text )
...
@@ -210,6 +210,26 @@ void UniXML::setProp(xmlNode* node, const string& name, const string& text )
::
xmlSetProp
(
node
,
(
const
xmlChar
*
)
name
.
c_str
(),
(
const
xmlChar
*
)
text
.
c_str
());
::
xmlSetProp
(
node
,
(
const
xmlChar
*
)
name
.
c_str
(),
(
const
xmlChar
*
)
text
.
c_str
());
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
UniXMLPropList
UniXML
::
getPropList
(
xmlNode
*
node
)
{
UniXMLPropList
lst
;
if
(
!
node
)
return
std
::
move
(
lst
);
xmlAttr
*
attribute
=
node
->
properties
;
while
(
attribute
)
{
xmlChar
*
value
=
::
xmlNodeListGetString
(
node
->
doc
,
attribute
->
children
,
1
);
const
std
::
string
nm
(
(
const
char
*
)
attribute
->
name
);
const
std
::
string
val
(
(
const
char
*
)
value
);
lst
.
push_back
(
{
nm
,
val
}
);
xmlFree
(
value
);
attribute
=
attribute
->
next
;
}
return
std
::
move
(
lst
);
}
// -----------------------------------------------------------------------------
xmlNode
*
UniXML
::
createChild
(
xmlNode
*
node
,
const
string
&
title
,
const
string
&
text
)
xmlNode
*
UniXML
::
createChild
(
xmlNode
*
node
,
const
string
&
title
,
const
string
&
text
)
{
{
return
::
xmlNewChild
(
node
,
NULL
,
(
const
xmlChar
*
)
title
.
c_str
(),
(
const
xmlChar
*
)
text
.
c_str
());
return
::
xmlNewChild
(
node
,
NULL
,
(
const
xmlChar
*
)
title
.
c_str
(),
(
const
xmlChar
*
)
text
.
c_str
());
...
@@ -526,6 +546,11 @@ void UniXML_iterator::goEnd() noexcept
...
@@ -526,6 +546,11 @@ void UniXML_iterator::goEnd() noexcept
}
}
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
UniXMLPropList
UniXML_iterator
::
getPropList
()
const
{
return
UniXML
::
getPropList
(
curNode
);
}
// -------------------------------------------------------------------------
UniXML_iterator
::
operator
xmlNode
*
()
const
noexcept
UniXML_iterator
::
operator
xmlNode
*
()
const
noexcept
{
{
//ulog.< "current\n";
//ulog.< "current\n";
...
...
tests/test_unixml.cc
View file @
d5656600
#include <catch.hpp>
#include <catch.hpp>
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <iostream>
#include <iostream>
#include <sstream>
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include "Exceptions.h"
#include "Exceptions.h"
#include "UniXML.h"
#include "UniXML.h"
...
@@ -162,3 +163,32 @@ TEST_CASE("UniXML::iterator::find", "[unixml][iterator-find][basic]" )
...
@@ -162,3 +163,32 @@ TEST_CASE("UniXML::iterator::find", "[unixml][iterator-find][basic]" )
CHECK
(
sIt
.
find
(
"subnode"
)
);
CHECK
(
sIt
.
find
(
"subnode"
)
);
REQUIRE
(
sIt
.
getProp
(
"name"
)
==
"Test5"
);
REQUIRE
(
sIt
.
getProp
(
"name"
)
==
"Test5"
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"UniXML::iterator::getPropList"
,
"[unixml][iterator-proplist][basic]"
)
{
UniXML
uxml
(
"tests_unixml.xml"
);
REQUIRE
(
uxml
.
isOpen
()
);
UniXML
::
iterator
it
=
uxml
.
begin
();
REQUIRE
(
it
.
find
(
"TestPropList"
)
!=
0
);
UniXML
::
PropList
lst
=
it
.
getPropList
();
REQUIRE
(
lst
.
size
()
==
5
);
std
::
ostringstream
n
;
std
::
ostringstream
v
;
for
(
size_t
i
=
0
;
i
<
5
;
i
++
)
{
n
.
str
(
""
);
n
<<
"prop"
<<
(
i
+
1
);
v
.
str
(
""
);
v
<<
"val"
<<
(
i
+
1
);
REQUIRE
(
lst
[
i
].
first
==
n
.
str
()
);
REQUIRE
(
lst
[
i
].
second
==
v
.
str
()
);
}
}
// -----------------------------------------------------------------------------
tests/tests_unixml.xml
View file @
d5656600
...
@@ -44,6 +44,8 @@
...
@@ -44,6 +44,8 @@
<subnode
name=
"Test4"
/>
<subnode
name=
"Test4"
/>
<TestPropList
prop1=
"val1"
prop2=
"val2"
prop3=
"val3"
prop4=
"val4"
prop5=
"val5"
/>
<TestProc
name=
"TestProc1"
<TestProc
name=
"TestProc1"
on_s=
"Input1_S"
on_s=
"Input1_S"
lamp_c=
"Lamp58_C"
lamp_c=
"Lamp58_C"
...
...
uniset2.includes
View file @
d5656600
...
@@ -16,6 +16,7 @@ extensions/tests/SMemoryTest
...
@@ -16,6 +16,7 @@ extensions/tests/SMemoryTest
extensions/UNetUDP
extensions/UNetUDP
extensions/UniNetwork
extensions/UniNetwork
include
include
include/libxml2/libxml
include/modbus
include/modbus
python/lib/pyUniSet
python/lib/pyUniSet
src/Log
src/Log
...
...
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