mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Made the attribute_list of the xml parser a little more friendly by allowing
you to ask for attributes that don't exist and get a defined behavior (an exception being thrown) rather than it being a contract violation.
This commit is contained in:
parent
a1eea964b6
commit
4b2eea202c
@ -49,7 +49,7 @@ namespace dlib
|
||||
|
||||
public:
|
||||
|
||||
// These typedefs are here for backwards compatibily with previous versions of
|
||||
// These typedefs are here for backwards compatibly with previous versions of
|
||||
// dlib.
|
||||
typedef xml_parser kernel_1a;
|
||||
typedef xml_parser kernel_1a_c;
|
||||
@ -103,7 +103,10 @@ namespace dlib
|
||||
const std::string& key
|
||||
) const
|
||||
{
|
||||
if (is_in_list(key))
|
||||
return list[key];
|
||||
else
|
||||
throw xml_attribute_list_error("No XML attribute named " + key + " is present in tag.");
|
||||
}
|
||||
|
||||
bool at_start (
|
||||
|
@ -6,10 +6,24 @@
|
||||
#include <string>
|
||||
#include "../interfaces/enumerable.h"
|
||||
#include "../interfaces/map_pair.h"
|
||||
#include "../error.h"
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
class xml_attribute_list_error : public dlib::error
|
||||
{
|
||||
/*!
|
||||
WHAT THIS OBJECT REPRESENTS
|
||||
This is an exception object thrown by attribute_list objects if you try to
|
||||
access a non-existent attribute.
|
||||
!*/
|
||||
public:
|
||||
xml_attribute_list_error(const std::string& msg) : dlib::error(msg){}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
@ -43,11 +57,12 @@ namespace dlib
|
||||
const std::string& key
|
||||
) const =0;
|
||||
/*!
|
||||
requires
|
||||
- is_in_list(key) == true
|
||||
ensures
|
||||
- returns a const reference to the value associated with the
|
||||
attribute named key.
|
||||
if (is_in_list(key) == true) then
|
||||
- returns a const reference to the value associated with the attribute
|
||||
named key.
|
||||
- else
|
||||
- throws xml_attribute_list_error
|
||||
!*/
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user