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
573defc9
Commit
573defc9
authored
Jun 05, 2021
by
Pavel Vainerman
Committed by
Pavel Vainerman
Jun 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[conf]: supported external xml for configuration, supported create xml from text
parent
2455feab
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
2 deletions
+63
-2
Configuration.h
include/Configuration.h
+4
-0
UniXML.h
include/UniXML.h
+3
-0
Configuration.cc
src/Core/Configuration.cc
+0
-0
UniXML.cc
src/Various/UniXML.cc
+29
-2
test_unixml.cc
tests/test_unixml.cc
+27
-0
No files found.
include/Configuration.h
View file @
573defc9
...
...
@@ -52,6 +52,9 @@ namespace uniset
/*! конфигурирование xml-файлом ( предпочтительный способ ) */
Configuration
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
xmlfile
=
""
);
/*! конфигурирование внешним xml */
Configuration
(
int
argc
,
const
char
*
const
*
argv
,
std
::
shared_ptr
<
UniXML
>
xml
);
/*! конфигурирование xml-файлом */
Configuration
(
int
argc
,
const
char
*
const
*
argv
,
std
::
shared_ptr
<
ObjectIndex
>
oind
,
const
std
::
string
&
xmlfile
=
""
);
...
...
@@ -251,6 +254,7 @@ namespace uniset
/*! инициализация "глобальной" конфигурации */
std
::
shared_ptr
<
Configuration
>
uniset_init
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
xmlfile
=
"configure.xml"
);
std
::
shared_ptr
<
Configuration
>
uniset_init
(
int
argc
,
const
char
*
const
*
argv
,
std
::
shared_ptr
<
UniXML
>
xml
);
// --------------------------------------------------------------------------
}
// end of uniset namespace
// --------------------------------------------------------------------------
...
...
include/UniXML.h
View file @
573defc9
...
...
@@ -139,6 +139,9 @@ namespace uniset
std
::
string
getFileName
()
const
noexcept
;
void
createFromText
(
const
std
::
string
&
text
);
// Создать новый XML-документ
void
newDoc
(
const
std
::
string
&
root_node
,
const
std
::
string
&
xml_ver
=
"1.0"
);
...
...
src/Core/Configuration.cc
View file @
573defc9
This diff is collapsed.
Click to expand it.
src/Various/UniXML.cc
View file @
573defc9
...
...
@@ -49,7 +49,7 @@ UniXML::UniXML(const string& fname):
{
open
(
filename
);
}
// -----------------------------------------------------------------------------
UniXML
::
UniXML
()
{
}
...
...
@@ -64,7 +64,7 @@ string UniXML::getFileName() const noexcept
return
filename
;
}
// -----------------------------------------------------------------------------
void
UniXML
::
newDoc
(
const
string
&
root_node
,
const
string
&
xml_ver
)
void
UniXML
::
newDoc
(
const
string
&
root_node
,
const
string
&
xml_ver
)
{
assert
(
doc
==
nullptr
);
// предыдущий doc не удален из памяти
...
...
@@ -107,6 +107,33 @@ UniXML::iterator UniXML::end() noexcept
return
iterator
(
NULL
);
}
// -----------------------------------------------------------------------------
static
void
suppress
(
void
*
ctx
,
const
char
*
msg
,
...)
{
}
// -----------------------------------------------------------------------------
void
UniXML
::
createFromText
(
const
std
::
string
&
text
)
{
assert
(
doc
==
nullptr
);
// предыдущий doc не удален из памяти
// hide console errors
// xmlSetGenericErrorFunc(NULL,suppress);
xmlKeepBlanksDefault
(
0
);
// Can read files in any encoding, recode to UTF-8 internally
xmlDoc
*
d
=
xmlParseDoc
((
const
xmlChar
*
)
text
.
c_str
());
if
(
d
==
NULL
)
throw
SystemError
(
"UniXML(createFromText): parse error"
);
doc
=
std
::
unique_ptr
<
xmlDoc
,
UniXMLDocDeleter
>
(
d
);
// Support for XInclude (see eterbug #6304)
// main tag must to have follow property: xmlns:xi="http://www.w3.org/2001/XInclude"
//For include: <xi:include href="test2.xml"/>
xmlXIncludeProcess
(
doc
.
get
());
}
// -----------------------------------------------------------------------------
void
UniXML
::
open
(
const
string
&
_filename
)
{
assert
(
doc
==
nullptr
);
// предыдущий doc не удален из памяти
...
...
tests/test_unixml.cc
View file @
573defc9
...
...
@@ -210,3 +210,30 @@ TEST_CASE("UniXML::iterator::getPropList", "[unixml][iterator-proplist][basic]"
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"UniXML createFromText"
,
"[unixml][createFromText]"
)
{
UniXML
uxml
;
CHECK_FALSE
(
uxml
.
isOpen
()
);
const
string
text
=
\
"<?xml version=
\"
1.0
\"
encoding=
\"
utf-8
\"
?> \
<TestConf xmlns:xi=
\"
http://www.w3.org/2001/XInclude
\"
> \
<UserData/> \
<UniSet> \
</UniSet> \
</TestConf>"
;
REQUIRE_NOTHROW
(
uxml
.
createFromText
(
text
));
CHECK
(
uxml
.
isOpen
()
);
xmlNode
*
cnode
=
uxml
.
findNode
(
uxml
.
getFirstNode
(),
"UniSet"
);
CHECK
(
cnode
!=
NULL
);
uxml
.
close
();
CHECK_FALSE
(
uxml
.
isOpen
()
);
const
string
badtext
=
"<?xml version="
;
REQUIRE_THROWS_AS
(
uxml
.
createFromText
(
badtext
),
uniset
::
SystemError
&
);
}
// -----------------------------------------------------------------------------
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