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
910b4860
Commit
910b4860
authored
Jan 20, 2011
by
Pavel Turchinskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes of UniXML_iterator are complete. Added testing files.
parent
91d29eb0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
290 additions
and
11 deletions
+290
-11
UniXML.h
include/UniXML.h
+22
-10
UniXML.cc
src/Various/UniXML.cc
+128
-0
Makefile.am
tests/Makefile.am
+5
-1
iterator_test.cc
tests/iterator_test.cc
+71
-0
iterator_test.xml
tests/iterator_test.xml
+64
-0
No files found.
include/UniXML.h
View file @
910b4860
...
...
@@ -39,7 +39,7 @@
#include <libxml/tree.h>
class
UniXML_iterator
class
UniXML_iterator
:
public
std
::
iterator
<
std
::
bidirectional_iterator_tag
,
xmlNode
,
ptrdiff_t
,
xmlNode
*
,
xmlNode
&>
{
public
:
UniXML_iterator
(
xmlNode
*
node
)
:
...
...
@@ -54,6 +54,9 @@ class UniXML_iterator
int
getPIntProp
(
const
std
::
string
name
,
int
def
)
const
;
void
setProp
(
const
std
::
string
name
,
const
std
::
string
text
);
bool
findName
(
const
std
::
string
node
,
const
std
::
string
searchname
);
bool
find
(
const
std
::
string
searchnode
);
/*! Перейти к следующему узлу. Возвращает false, если некуда перейти */
bool
goNext
();
...
...
@@ -67,16 +70,12 @@ class UniXML_iterator
bool
canNext
();
// Перейти к следующему узлу
void
operator
++
()
{
goNext
();
}
UniXML_iterator
operator
++
(
int
);
UniXML_iterator
operator
++
();
// Перейти к предыдущему узлу
void
operator
--
()
{
goPrev
();
}
UniXML_iterator
operator
--
(
int
);
UniXML_iterator
operator
--
();
/*! Перейти на один уровень выше
\note Если перейти не удалось, итератор остаётся указывать на прежний узел
...
...
@@ -121,7 +120,7 @@ class UniXML_iterator
while
(
canNext
()){
goNext
();}
}
pr
ivate
:
pr
otected
:
xmlNode
*
curNode
;
};
...
...
@@ -129,11 +128,24 @@ class UniXML
{
public
:
typedef
UniXML_iterator
iterator
;
inline
xmlNode
*
getFirstNode
()
{
return
xmlDocGetRootElement
(
doc
);
}
/*! возвращает итератор на самый первый узел документа */
inline
iterator
begin
()
{
return
iterator
(
getFirstNode
());
}
inline
iterator
end
()
{
return
iterator
(
NULL
);
}
// Загружает указанный файл
void
open
(
const
std
::
string
filename
);
...
...
src/Various/UniXML.cc
View file @
910b4860
...
...
@@ -415,4 +415,131 @@ void UniXML_iterator::setProp( const string name, const string text )
{
UniXML
::
setProp
(
curNode
,
name
,
text
);
}
// -------------------------------------------------------------------------
bool
UniXML_iterator
::
findName
(
const
std
::
string
node
,
const
std
::
string
searchname
)
{
while
(
find
(
node
)
)
{
if
(
searchname
==
getProp
(
"name"
)
)
return
true
;
}
return
false
;
}
// -------------------------------------------------------------------------
bool
UniXML_iterator
::
find
(
const
std
::
string
searchnode
)
{
while
(
curNode
!=
NULL
)
{
while
(
curNode
->
children
)
{
curNode
=
curNode
->
children
;
if
(
searchnode
==
(
const
char
*
)
curNode
->
name
)
return
true
;
}
while
(
!
curNode
->
next
&&
curNode
->
parent
)
{
curNode
=
curNode
->
parent
;
}
curNode
=
curNode
->
next
;
if
(
curNode
&&
searchnode
==
(
const
char
*
)
curNode
->
name
)
{
return
true
;
}
}
return
false
;
}
// -------------------------------------------------------------------------
UniXML_iterator
UniXML_iterator
::
operator
++
()
{
if
(
!
curNode
->
next
)
{
curNode
=
curNode
->
next
;
return
*
this
;
}
for
(;;)
{
curNode
=
curNode
->
next
;
if
(
getName
()
==
"text"
||
getName
()
==
"comment"
)
continue
;
else
break
;
}
return
*
this
;
}
UniXML_iterator
UniXML_iterator
::
operator
++
(
int
)
{
UniXML_iterator
it
=
*
this
;
if
(
!
curNode
->
next
)
{
curNode
=
curNode
->
next
;
return
it
;
}
for
(;;)
{
curNode
=
curNode
->
next
;
if
(
getName
()
==
"text"
||
getName
()
==
"comment"
)
continue
;
else
break
;
}
return
it
;
}
// -------------------------------------------------------------------------
UniXML_iterator
UniXML_iterator
::
operator
--
()
{
if
(
!
curNode
->
prev
)
{
curNode
=
curNode
->
prev
;
return
*
this
;
}
for
(;;)
{
curNode
=
curNode
->
prev
;
if
(
getName
()
==
"text"
||
getName
()
==
"comment"
)
continue
;
else
break
;
}
return
*
this
;
}
UniXML_iterator
UniXML_iterator
::
operator
--
(
int
)
{
UniXML_iterator
it
=
*
this
;
if
(
!
curNode
->
prev
)
{
curNode
=
curNode
->
prev
;
return
it
;
}
for
(;;)
{
curNode
=
curNode
->
prev
;
if
(
getName
()
==
"text"
||
getName
()
==
"comment"
)
continue
;
else
break
;
}
return
it
;
}
// -------------------------------------------------------------------------------
\ No newline at end of file
tests/Makefile.am
View file @
910b4860
...
...
@@ -4,7 +4,7 @@
SUBDIRS
=
JrnTests
noinst_PROGRAMS
=
passivetimer unixml ui umutex conftest
noinst_PROGRAMS
=
passivetimer unixml ui umutex conftest
iterator_test
passivetimer_SOURCES
=
passivetimer.cc
passivetimer_LDADD
=
$(top_builddir)
/lib/libUniSet.la
...
...
@@ -14,6 +14,10 @@ unixml_SOURCES = unixml.cc
unixml_LDADD
=
$(top_builddir)
/lib/libUniSet.la
unixml_CPPFLAGS
=
-I
$(top_builddir)
/include
iterator_test_SOURCES
=
iterator_test.cc
iterator_test_LDADD
=
$(top_builddir)
/lib/libUniSet.la
iterator_test_CPPFLAGS
=
-I
$(top_builddir)
/include
ui_SOURCES
=
ui.cc
ui_LDADD
=
$(top_builddir)
/lib/libUniSet.la
ui_CPPFLAGS
=
-I
$(top_builddir)
/include
...
...
tests/iterator_test.cc
0 → 100644
View file @
910b4860
#include <iostream>
#include <algorithm>
using
namespace
std
;
#include "Exceptions.h"
#include "UniXML.h"
#include "UniSetTypes.h"
void
check
(
const
std
::
string
name
,
const
std
::
string
true_res
,
const
std
::
string
your_res
)
{
cout
<<
name
<<
endl
;
cout
<<
"Correct result: "
<<
true_res
<<
endl
;
if
(
your_res
==
true_res
)
cout
<<
"Your result: "
<<
your_res
<<
"
\n
"
<<
endl
;
else
cout
<<
"Your result - ERROR!"
<<
"
\n
"
<<
endl
;
}
void
myf
(
xmlNode
it
)
{
cout
<<
it
.
name
<<
endl
;
}
int
main
()
{
UniXML
xml
(
"iterator_test.xml"
);
UniXML
::
iterator
it
=
xml
.
begin
();
it
.
find
(
"messages"
);
check
(
"Check find():"
,
"messages"
,
it
.
getName
()
);
it
=
xml
.
begin
();
it
.
find
(
"d7"
);
check
(
"Check find():"
,
"d7"
,
it
.
getName
()
);
it
=
xml
.
begin
();
it
.
findName
(
"c5"
,
"6abc"
);
check
(
"Check findName():"
,
"c5"
,
it
.
getName
()
);
it
=
xml
.
begin
();
it
.
findName
(
"messages"
,
"messages"
);
check
(
"Check findName():"
,
"messages"
,
it
.
getName
()
);
it
=
xml
.
begin
();
it
.
find
(
"UniSet"
);
it
++
;
++
it
;
check
(
"Check iterator ++ :"
,
"ObjectsMap"
,
it
.
getName
()
);
it
=
xml
.
begin
();
it
.
find
(
"testII"
);
it
++
;
it
--
;
--
it
;
check
(
"Check iterator -- :"
,
"a2"
,
it
.
getName
()
);
it
=
xml
.
begin
();
it
.
goChildren
();
cout
<<
"Check algorythm 'for_each()':
\n
"
;
for_each
(
it
,
xml
.
end
(),
myf
);
cout
<<
"
\n
Correct result for algoryhtm 'for_each()':
\n
"
<<
"UniSet
\n
"
<<
"dlog
\n
"
<<
"ObjectsMap
\n
"
<<
"messages
\n
"
;
return
0
;
}
tests/iterator_test.xml
0 → 100644
View file @
910b4860
<?xml version = '1.0' encoding = 'UTF-8' ?>
<UNISETPLC>
<UniSet>
<test
name=
"testattr_0"
>
<a1
name=
"1abc"
/>
<a2
name=
"2abc"
/>
<testI
name=
"testattr_1"
>
<b3
name=
"3abc"
/>
<a2
name=
"3abc"
/>
<testII
name=
"testattr_2"
>
<c4
name=
"4abc"
/>
<c5
name=
"5abc"
/>
</testII>
<testIII
name=
"testattr_3"
>
<d6
name=
"6abc"
/>
<d7
name=
"7abc"
/>
<a2
name=
"4abc"
/>
<c5
name=
"6abc"
/>
</testIII>
</testI>
<testIV
name=
"testattr_4"
>
<e8
name=
"8abc"
/>
<e9>
<f10
name=
"10abc"
>
</f10>
</e9>
</testIV>
<a2
name=
"5abc"
/>
<c5
name=
"7abc"
/>
</test>
</UniSet>
<dlog
name=
"dlog"
levels=
""
file=
""
/>
<ObjectsMap
idfromfile=
"1"
>
</ObjectsMap>
<messages
name=
"messages"
idfromfile=
"1"
>
</messages>
</UNISETPLC>
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