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
b4162e34
Commit
b4162e34
authored
Aug 27, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(UniXML): небольшой рефакторинг
parent
1cacc5e6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
147 additions
and
179 deletions
+147
-179
UniXML.h
include/UniXML.h
+22
-106
UniXML.cc
src/Various/UniXML.cc
+125
-73
No files found.
include/UniXML.h
View file @
b4162e34
...
...
@@ -30,6 +30,7 @@
#include <assert.h>
#include <string>
#include <cstddef>
#include <memory>
#include <libxml/parser.h>
#include <libxml/tree.h>
...
...
@@ -45,7 +46,6 @@ class 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
);
/// if value if not positive ( <= 0 ), returns def
int
getPIntProp
(
const
std
::
string
&
name
,
int
def
);
...
...
@@ -66,25 +66,7 @@ class UniXML_iterator:
bool
canPrev
();
bool
canNext
();
#if 0
friend inline bool operator==(const UniXML_iterator& lhs, const UniXML_iterator& rhs)
{
return ( lhs.curNode != 0 && rhs.curNode != 0 && lhs.curNode == rhs.curNode );
}
friend inline bool operator!=(const UniXML_iterator& lhs, const UniXML_iterator& rhs)
{
return !(lhs == rhs);
}
inline bool operator==(int a)
{
if( a == 0 )
return (curNode == NULL);
return false;
}
#endif
// Перейти к следующему узлу
UniXML_iterator
&
operator
+
(
int
);
UniXML_iterator
&
operator
++
(
int
);
...
...
@@ -108,50 +90,19 @@ class UniXML_iterator:
bool
goChildren
();
// Получить текущий узел
xmlNode
*
getCurrent
()
{
return
curNode
;
}
xmlNode
*
getCurrent
();
// Получить название текущего узла
inline
const
std
::
string
getName
()
const
{
if
(
curNode
)
{
if
(
!
curNode
->
name
)
return
""
;
return
(
char
*
)
curNode
->
name
;
}
const
std
::
string
getName
()
const
;
const
std
::
string
getContent
()
const
;
return
""
;
}
operator
xmlNode
*
()
const
;
const
std
::
string
getContent
()
const
;
void
goBegin
();
void
goEnd
();
inline
operator
xmlNode
*
()
const
{
//ulog.< "current\n";
return
curNode
;
}
inline
void
goBegin
()
{
while
(
canPrev
())
{
goPrev
();
}
}
inline
void
goEnd
()
{
while
(
canNext
())
{
goNext
();
}
}
private
:
protected
:
xmlNode
*
curNode
;
};
// --------------------------------------------------------------------------
...
...
@@ -161,57 +112,34 @@ class UniXML
typedef
UniXML_iterator
iterator
;
inline
xmlNode
*
getFirstNode
()
{
return
xmlDocGetRootElement
(
doc
);
}
inline
xmlNode
*
getFirstNode
()
const
{
return
xmlDocGetRootElement
(
doc
);
}
UniXML
(
const
std
::
string
&
filename
);
UniXML
();
~
UniXML
();
xmlNode
*
getFirstNode
();
xmlNode
*
getFirstNode
()
const
;
/*! возвращает итератор на самый первый узел документа */
inline
iterator
begin
()
{
return
iterator
(
getFirstNode
());
}
inline
iterator
end
()
{
return
iterator
(
NULL
);
}
iterator
begin
();
iterator
end
();
// Загружает указанный файл
void
open
(
const
std
::
string
&
filename
);
void
open
(
const
std
::
string
&
filename
);
void
close
();
inline
bool
isOpen
()
const
{
return
doc
!=
0
;
}
UniXML
(
const
std
::
string
&
filename
);
UniXML
();
~
UniXML
();
bool
isOpen
()
const
;
xmlDoc
*
doc
;
inline
std
::
string
getFileName
()
const
{
return
filename
;
}
std
::
string
getFileName
()
const
;
// Создать новый XML-документ
void
newDoc
(
const
std
::
string
&
root_node
,
std
::
string
xml_ver
=
"1.0"
);
void
newDoc
(
const
std
::
string
&
root_node
,
const
std
::
string
&
xml_ver
=
"1.0"
);
// Получить свойство 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
static
int
getPIntProp
(
const
xmlNode
*
node
,
const
std
::
string
&
name
,
int
def
);
...
...
@@ -240,27 +168,15 @@ class UniXML
// После проверки исправить рекурсивный алгоритм на обычный,
// используя ->parent
xmlNode
*
findNode
(
xmlNode
*
node
,
const
std
::
string
&
searchnode
,
const
std
::
string
&
name
=
""
)
const
;
xmlNode
*
findNodeUtf8
(
xmlNode
*
node
,
const
std
::
string
&
searchnode
,
const
std
::
string
&
name
=
""
)
const
;
// ??
//width means number of nodes of the same level as node in 1-st parameter (width number includes first node)
//depth means number of times we can go to the children, if 0 we can't go only to elements of the same level
xmlNode
*
extFindNode
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
std
::
string
&
searchnode
,
const
std
::
string
&
name
=
""
,
bool
top
=
true
)
const
;
xmlNode
*
extFindNodeUtf8
(
xmlNode
*
node
,
int
depth
,
int
width
,
const
std
::
string
&
searchnode
,
const
std
::
string
&
name
=
""
,
bool
top
=
true
)
const
;
protected
:
std
::
string
filename
;
// Преобразование текстовой строки из XML в строку нашего внутреннего представления
static
std
::
string
xml2local
(
const
std
::
string
&
text
);
// Преобразование текстовой строки из нашего внутреннего представления в строку для XML
// Возвращает указатель на временный буфер, который один на все вызовы функции.
static
const
xmlChar
*
local2xml
(
const
std
::
string
&
text
);
static
std
::
string
local2utf8
(
const
std
::
string
&
text
);
static
size_t
recur
;
std
::
shared_ptr
<
xmlDoc
>
doc
=
{
nullptr
};
};
// --------------------------------------------------------------------------
#endif
src/Various/UniXML.cc
View file @
b4162e34
This diff is collapsed.
Click to expand it.
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