Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
2e67aa54
Commit
2e67aa54
authored
Nov 17, 2012
by
Davis King
Browse files
Turned the xml_parser into a single implementation component.
parent
f9e63c9d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
265 deletions
+56
-265
dlib/xml_parser.h
dlib/xml_parser.h
+0
-44
dlib/xml_parser/xml_parser_kernel_1.h
dlib/xml_parser/xml_parser_kernel_1.h
+56
-157
dlib/xml_parser/xml_parser_kernel_c.h
dlib/xml_parser/xml_parser_kernel_c.h
+0
-64
No files found.
dlib/xml_parser.h
View file @
2e67aa54
...
...
@@ -7,51 +7,7 @@
#include "xml_parser/xml_parser_kernel_interfaces.h"
#include "xml_parser/xml_parser_kernel_1.h"
#include "xml_parser/xml_parser_kernel_c.h"
#include "map.h"
#include "stack.h"
#include "sequence.h"
#include "memory_manager.h"
namespace
dlib
{
class
xml_parser
{
typedef
map
<
std
::
string
,
std
::
string
,
memory_manager
<
char
>::
kernel_2a
>::
kernel_1b
map1a
;
typedef
map
<
std
::
string
,
std
::
string
,
memory_manager
<
char
>::
kernel_2a
>::
kernel_1b_c
map1a_c
;
typedef
stack
<
std
::
string
,
memory_manager
<
char
>::
kernel_2a
>::
kernel_1a
stack1a
;
typedef
sequence
<
document_handler
*>::
kernel_2a
seq_dh2a
;
typedef
sequence
<
error_handler
*>::
kernel_2a
seq_eh2a
;
// A version that uses the checked map. This way there is checking on the attribute
// list that gets passed back to the user.
typedef
xml_parser_kernel_1
<
map1a_c
,
stack1a
,
seq_dh2a
,
seq_eh2a
>
kernel_1a_c_impl
;
xml_parser
()
{}
public:
//----------- kernels ---------------
// kernel_1a
typedef
xml_parser_kernel_1
<
map1a
,
stack1a
,
seq_dh2a
,
seq_eh2a
>
kernel_1a
;
typedef
xml_parser_kernel_c
<
kernel_1a_c_impl
>
kernel_1a_c
;
};
}
#endif // DLIB_XML_PARSEr_
dlib/xml_parser/xml_parser_kernel_1.h
View file @
2e67aa54
...
...
@@ -3,46 +3,30 @@
#ifndef DLIB_XML_PARSER_KERNEl_1_
#define DLIB_XML_PARSER_KERNEl_1_
#include "xml_parser_kernel_abstract.h"
#include <string>
#include <iostream>
#include "xml_parser_kernel_interfaces.h"
#include "xml_parser_kernel_abstract.h"
#include "../algs.h"
#include <cstdio>
#include "../map.h"
#include "../stack.h"
#include "../sequence.h"
#include "../memory_manager.h"
namespace
dlib
{
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
class
xml_parser_kernel_1
class
xml_parser
{
typedef
dlib
::
map
<
std
::
string
,
std
::
string
,
memory_manager
<
char
>::
kernel_2a
>::
kernel_1b
map
;
typedef
dlib
::
stack
<
std
::
string
,
memory_manager
<
char
>::
kernel_2a
>::
kernel_1a
stack
;
typedef
sequence
<
document_handler
*>::
kernel_2a
seq_dh
;
typedef
sequence
<
error_handler
*>::
kernel_2a
seq_eh
;
/*!
REQUIREMENTS ON map
is an implementation of map/map_kernel_abstract.h or
is an implementation of hash_map/hash_map_kernel_abstract.h and
is instantiated to map items of type std::string to std::string
REQUIREMENTS ON stack
is an implementation of stack/stack_kernel_abstract.h and
is instantiated with std::string
REQUIREMENTS ON seq_dh
is an implementation of sequence/sequence_kernel_abstract.h and
is instantiated with document_handler*
REQUIREMENTS ON seq_eh
is an implementation of sequence/sequence_kernel_abstract.h and
is instantiated with error_handler*
INITIAL VALUE
dh_list.size() == 0
eh_list.size() == 0
...
...
@@ -53,7 +37,6 @@ namespace dlib
eh_list == a sequence of pointers to all the error_handlers that
have been added to the xml_parser
use of template parameters:
map is used to implement the attribute_list interface
stack is used just inside the parse function
seq_dh is used to make the dh_list member variable
...
...
@@ -64,31 +47,35 @@ namespace dlib
public:
// These typedefs are here for backwards compatibily with previous versions of
// dlib.
typedef
xml_parser
kernel_1a
;
typedef
xml_parser
kernel_1a_c
;
xml_parser
_kernel_1
(
)
;
xml_parser
(
)
{}
virtual
~
xml_parser
_kernel_1
(
)
;
virtual
~
xml_parser
(
)
{}
void
clear
(
inline
void
clear
(
);
void
parse
(
inline
void
parse
(
std
::
istream
&
in
);
void
add_document_handler
(
inline
void
add_document_handler
(
document_handler
&
item
);
void
add_error_handler
(
inline
void
add_error_handler
(
error_handler
&
item
);
void
swap
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
item
inline
void
swap
(
xml_parser
&
item
);
...
...
@@ -173,7 +160,7 @@ namespace dlib
// private member functions
void
get_next_token
(
inline
void
get_next_token
(
std
::
istream
&
in
,
std
::
string
&
token_text
,
int
&
token_kind
,
...
...
@@ -188,7 +175,7 @@ namespace dlib
only for chars tokens
!*/
int
parse_element
(
inline
int
parse_element
(
const
std
::
string
&
token
,
std
::
string
&
name
,
attrib_list
&
atts
...
...
@@ -204,7 +191,7 @@ namespace dlib
returns -1 if it failed to parse token
!*/
int
parse_pi
(
inline
int
parse_pi
(
const
std
::
string
&
token
,
std
::
string
&
target
,
std
::
string
&
data
...
...
@@ -220,7 +207,7 @@ namespace dlib
returns -1 if it failed to parse token
!*/
int
parse_element_end
(
inline
int
parse_element_end
(
const
std
::
string
&
token
,
std
::
string
&
name
);
...
...
@@ -260,22 +247,16 @@ namespace dlib
// -----------------------------------
// restricted functions: assignment and copy construction
xml_parser
_kernel_1
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
);
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
operator
=
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
xml_parser
(
xml_parser
&
);
xml_parser
&
operator
=
(
xml_parser
&
);
};
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
inline
void
swap
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
a
,
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
b
xml_parser
&
a
,
xml_parser
&
b
)
{
a
.
swap
(
b
);
}
...
...
@@ -285,41 +266,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
xml_parser_kernel_1
(
)
{
}
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
~
xml_parser_kernel_1
(
)
{
}
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
void
xml_parser
::
clear
(
)
{
...
...
@@ -330,17 +277,17 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
void
xml_parser
::
parse
(
std
::
istream
&
in
)
{
DLIB_CASSERT
(
in
.
fail
()
==
false
,
"
\t
void xml_parser::parse"
<<
"
\n\t
the input stream must not be in the fail state"
<<
"
\n\t
this: "
<<
this
);
// save which exceptions in will throw and make it so it won't throw any
// for the life of this function
...
...
@@ -633,13 +580,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
void
xml_parser
::
add_document_handler
(
document_handler
&
item
)
...
...
@@ -650,13 +591,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
void
xml_parser
::
add_error_handler
(
error_handler
&
item
)
...
...
@@ -667,15 +602,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
void
xml_parser
::
swap
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
item
xml_parser
&
item
)
{
dh_list
.
swap
(
item
.
dh_list
);
...
...
@@ -688,13 +617,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
void
xml_parser
::
get_next_token
(
std
::
istream
&
in
,
std
::
string
&
token_text
,
...
...
@@ -1114,13 +1037,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
int
xml_parser
::
parse_element
(
const
std
::
string
&
token
,
std
::
string
&
name
,
...
...
@@ -1277,13 +1194,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
int
xml_parser
::
parse_pi
(
const
std
::
string
&
token
,
std
::
string
&
target
,
...
...
@@ -1325,13 +1236,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
int
xml_parser
::
parse_element_end
(
const
std
::
string
&
token
,
std
::
string
&
name
...
...
@@ -1354,13 +1259,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
int
xml_parser
::
change_entity
(
std
::
istream
&
in
)
...
...
dlib/xml_parser/xml_parser_kernel_c.h
deleted
100644 → 0
View file @
f9e63c9d
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_XML_PARSER_KERNEL_C_
#define DLIB_XML_PARSER_KERNEL_C_
#include "xml_parser_kernel_abstract.h"
#include <string>
#include <iostream>
#include "../algs.h"
#include "../assert.h"
namespace
dlib
{
template
<
typename
xml_parser_base
>
class
xml_parser_kernel_c
:
public
xml_parser_base
{
public:
void
parse
(
std
::
istream
&
in
);
};
template
<
typename
xml_parser_base
>
inline
void
swap
(
xml_parser_kernel_c
<
xml_parser_base
>&
a
,
xml_parser_kernel_c
<
xml_parser_base
>&
b
)
{
a
.
swap
(
b
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
xml_parser_base
>
void
xml_parser_kernel_c
<
xml_parser_base
>::
parse
(
std
::
istream
&
in
)
{
DLIB_CASSERT
(
in
.
fail
()
==
false
,
"
\t
void xml_parser::parse"
<<
"
\n\t
the input stream must not be in the fail state"
<<
"
\n\t
this: "
<<
this
);
return
xml_parser_base
::
parse
(
in
);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_XML_PARSER_KERNEL_C_
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