File: mxml_error.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (96 lines) | stat: -rw-r--r-- 2,624 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
   Mini XML lib PLUS for C++

   Error class - implementation

   Author: Giancarlo Niccolai <gian@niccolai.ws>
*/

#include <mxml_error.h>

namespace MXML {

Error::Error( const codes code, const Element *generator ):
   m_code( code )
{
   m_beginLine = generator->beginLine();   
   m_beginChar = generator->beginChar();
   m_line = generator->line();
   m_char = generator->character();
}

Error::~Error()
{
}

const Falcon::String Error::description() const
{
   switch( m_code )
   {
      case errNone: return "No error";
      case errIo: return "Input/output error";
      case errNomem: return "Not enough memory";
      case errOutChar: return "Character outside tags";
      case errInvalidNode: return "Invalid character as tag name";
      case errInvalidAtt: return "Invalid character as attribute name";
      case errMalformedAtt: return "Malformed attribute definition";
      case errInvalidChar: return "Invalid character";
      case errUnclosed: return "Unbalanced tag opening";
      case errUnclosedEntity: return "Unbalanced entity opening";
      case errWrongEntity: return "Escape/entity '&;' found";
      case errChildNotFound: return "Unexisting child request";
      case errAttrNotFound: return "Attribute name cannot be found";
      case errHyerarcy: return "Node is not in a hierarcy - no parent";
      case errCommentInvalid: return "Invalid comment ( -- sequence is not followed by '>')";
      case errMultipleXmlDecl: return "Multiple XML top node delcarations";
   }
   return "Undefined error code";
}

int Error::numericCode() const
{
   return ((int) m_code );
}

void Error::toString( Falcon::String &stream ) const
{
   switch( this->type() ) {
      case malformedError: stream = "MXML::MalformedError"; break;
      case ioError: stream = "MXML::IOError"; break;
      case notFoundError: stream = "MXML::NotFoundError"; break;
      default: stream = "MXML::Unknown error";
   }
   stream += " (";
   stream.writeNumber( (Falcon::int64) this->m_code );
   stream += "):";

   stream += this->description();

   if ( this->type() != notFoundError ) {
      describeLine( stream );
   }
   stream.append( '\n' );
}

void Error::describeLine( Falcon::String &stream ) const
{
   if ( m_beginLine )
   {
      stream += "at ";
      stream.writeNumber( (Falcon::int64) m_beginLine );
      stream += ":";
      stream.writeNumber( (Falcon::int64) m_beginChar );
   }

   if ( m_line )
   {
      stream += " (from  ";
      stream.writeNumber( (Falcon::int64) m_line );
      stream += ":";
      stream.writeNumber( (Falcon::int64) m_char );
      stream += ")";
   }
}

}