Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
2e67aa54
Commit
2e67aa54
authored
Nov 18, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turned the xml_parser into a single implementation component.
parent
f9e63c9d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
265 deletions
+56
-265
xml_parser.h
dlib/xml_parser.h
+0
-44
xml_parser_kernel_1.h
dlib/xml_parser/xml_parser_kernel_1.h
+56
-157
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 @@
...
@@ -7,51 +7,7 @@
#include "xml_parser/xml_parser_kernel_interfaces.h"
#include "xml_parser/xml_parser_kernel_interfaces.h"
#include "xml_parser/xml_parser_kernel_1.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_
#endif // DLIB_XML_PARSEr_
dlib/xml_parser/xml_parser_kernel_1.h
View file @
2e67aa54
...
@@ -3,46 +3,30 @@
...
@@ -3,46 +3,30 @@
#ifndef DLIB_XML_PARSER_KERNEl_1_
#ifndef DLIB_XML_PARSER_KERNEl_1_
#define DLIB_XML_PARSER_KERNEl_1_
#define DLIB_XML_PARSER_KERNEl_1_
#include "xml_parser_kernel_abstract.h"
#include <string>
#include <string>
#include <iostream>
#include <iostream>
#include "xml_parser_kernel_interfaces.h"
#include "xml_parser_kernel_interfaces.h"
#include "xml_parser_kernel_abstract.h"
#include "../algs.h"
#include "../algs.h"
#include <cstdio>
#include <cstdio>
#include "../map.h"
#include "../stack.h"
#include "../sequence.h"
#include "../memory_manager.h"
namespace
dlib
namespace
dlib
{
{
template
<
class
xml_parser
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
class
xml_parser_kernel_1
{
{
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
INITIAL VALUE
dh_list.size() == 0
dh_list.size() == 0
eh_list.size() == 0
eh_list.size() == 0
...
@@ -53,42 +37,45 @@ namespace dlib
...
@@ -53,42 +37,45 @@ namespace dlib
eh_list == a sequence of pointers to all the error_handlers that
eh_list == a sequence of pointers to all the error_handlers that
have been added to the xml_parser
have been added to the xml_parser
use of template parameters:
map is used to implement the attribute_list interface
map is used to implement the attribute_list interface
stack is used just inside the parse function
stack is used just inside the parse function
seq_dh is used to make the dh_list member variable
seq_dh is used to make the dh_list member variable
seq_eh is used to make the eh_list member variable
seq_eh is used to make the eh_list member variable
!*/
!*/
public
:
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
std
::
istream
&
in
);
);
void
add_document_handler
(
inline
void
add_document_handler
(
document_handler
&
item
document_handler
&
item
);
);
void
add_error_handler
(
inline
void
add_error_handler
(
error_handler
&
item
error_handler
&
item
);
);
void
swap
(
inline
void
swap
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
item
xml_parser
&
item
);
);
...
@@ -173,7 +160,7 @@ namespace dlib
...
@@ -173,7 +160,7 @@ namespace dlib
// private member functions
// private member functions
void
get_next_token
(
inline
void
get_next_token
(
std
::
istream
&
in
,
std
::
istream
&
in
,
std
::
string
&
token_text
,
std
::
string
&
token_text
,
int
&
token_kind
,
int
&
token_kind
,
...
@@ -188,7 +175,7 @@ namespace dlib
...
@@ -188,7 +175,7 @@ namespace dlib
only for chars tokens
only for chars tokens
!*/
!*/
int
parse_element
(
in
line
in
t
parse_element
(
const
std
::
string
&
token
,
const
std
::
string
&
token
,
std
::
string
&
name
,
std
::
string
&
name
,
attrib_list
&
atts
attrib_list
&
atts
...
@@ -204,7 +191,7 @@ namespace dlib
...
@@ -204,7 +191,7 @@ namespace dlib
returns -1 if it failed to parse token
returns -1 if it failed to parse token
!*/
!*/
int
parse_pi
(
in
line
in
t
parse_pi
(
const
std
::
string
&
token
,
const
std
::
string
&
token
,
std
::
string
&
target
,
std
::
string
&
target
,
std
::
string
&
data
std
::
string
&
data
...
@@ -220,7 +207,7 @@ namespace dlib
...
@@ -220,7 +207,7 @@ namespace dlib
returns -1 if it failed to parse token
returns -1 if it failed to parse token
!*/
!*/
int
parse_element_end
(
in
line
in
t
parse_element_end
(
const
std
::
string
&
token
,
const
std
::
string
&
token
,
std
::
string
&
name
std
::
string
&
name
);
);
...
@@ -260,22 +247,16 @@ namespace dlib
...
@@ -260,22 +247,16 @@ namespace dlib
// -----------------------------------
// -----------------------------------
// restricted functions: assignment and copy construction
// restricted functions: assignment and copy construction
xml_parser
_kernel_1
(
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
);
xml_parser
(
xml_parser
&
);
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
operator
=
(
xml_parser
&
operator
=
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
xml_parser
&
);
);
};
};
template
<
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
inline
void
swap
(
inline
void
swap
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
a
,
xml_parser
&
a
,
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
b
xml_parser
&
b
)
{
a
.
swap
(
b
);
}
)
{
a
.
swap
(
b
);
}
...
@@ -285,41 +266,7 @@ namespace dlib
...
@@ -285,41 +266,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
void
xml_parser
::
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
>::
clear
(
clear
(
)
)
{
{
...
@@ -330,17 +277,17 @@ namespace dlib
...
@@ -330,17 +277,17 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
void
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
parse
(
parse
(
std
::
istream
&
in
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
// save which exceptions in will throw and make it so it won't throw any
// for the life of this function
// for the life of this function
...
@@ -633,13 +580,7 @@ namespace dlib
...
@@ -633,13 +580,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
void
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
add_document_handler
(
add_document_handler
(
document_handler
&
item
document_handler
&
item
)
)
...
@@ -650,13 +591,7 @@ namespace dlib
...
@@ -650,13 +591,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
void
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
add_error_handler
(
add_error_handler
(
error_handler
&
item
error_handler
&
item
)
)
...
@@ -667,15 +602,9 @@ namespace dlib
...
@@ -667,15 +602,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
void
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
swap
(
swap
(
xml_parser
_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>
&
item
xml_parser
&
item
)
)
{
{
dh_list
.
swap
(
item
.
dh_list
);
dh_list
.
swap
(
item
.
dh_list
);
...
@@ -688,13 +617,7 @@ namespace dlib
...
@@ -688,13 +617,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
void
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
void
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
get_next_token
(
get_next_token
(
std
::
istream
&
in
,
std
::
istream
&
in
,
std
::
string
&
token_text
,
std
::
string
&
token_text
,
...
@@ -1114,13 +1037,7 @@ namespace dlib
...
@@ -1114,13 +1037,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
int
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
parse_element
(
parse_element
(
const
std
::
string
&
token
,
const
std
::
string
&
token
,
std
::
string
&
name
,
std
::
string
&
name
,
...
@@ -1277,13 +1194,7 @@ namespace dlib
...
@@ -1277,13 +1194,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
int
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
parse_pi
(
parse_pi
(
const
std
::
string
&
token
,
const
std
::
string
&
token
,
std
::
string
&
target
,
std
::
string
&
target
,
...
@@ -1325,13 +1236,7 @@ namespace dlib
...
@@ -1325,13 +1236,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
int
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
parse_element_end
(
parse_element_end
(
const
std
::
string
&
token
,
const
std
::
string
&
token
,
std
::
string
&
name
std
::
string
&
name
...
@@ -1354,13 +1259,7 @@ namespace dlib
...
@@ -1354,13 +1259,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
int
xml_parser
::
typename
map
,
typename
stack
,
typename
seq_dh
,
typename
seq_eh
>
int
xml_parser_kernel_1
<
map
,
stack
,
seq_dh
,
seq_eh
>::
change_entity
(
change_entity
(
std
::
istream
&
in
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