2323
2424#include < sstream>
2525
26+ ErrorLogger::ErrorMessage::ErrorMessage ()
27+ {
28+
29+ }
30+ #include < iostream>
2631ErrorLogger::ErrorMessage::ErrorMessage (const std::list<FileLocation> &callStack, const std::string &severity, const std::string &msg, const std::string &id)
2732{
2833 _callStack = callStack;
@@ -31,6 +36,78 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack
3136 _id = id;
3237}
3338
39+ std::string ErrorLogger::ErrorMessage::serialize () const
40+ {
41+ std::ostringstream oss;
42+ oss << _id.length () << " " << _id;
43+ oss << _severity.length () << " " << _severity;
44+ oss << _msg.length () << " " << _msg;
45+ oss << _callStack.size () << " " ;
46+
47+ for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator tok = _callStack.begin (); tok != _callStack.end (); ++tok)
48+ {
49+ std::ostringstream smallStream;
50+ smallStream << (*tok).line << " :" << (*tok).file ;
51+ oss << smallStream.str ().length () << " " << smallStream.str ();
52+ }
53+ return oss.str ();
54+ }
55+
56+ bool ErrorLogger::ErrorMessage::deserialize (const std::string &data)
57+ {
58+ _callStack.clear ();
59+ std::istringstream iss (data);
60+ std::vector<std::string> results;
61+ while (iss.good ())
62+ {
63+ unsigned int len = 0 ;
64+ if (!(iss >> len))
65+ return false ;
66+
67+ iss.get ();
68+ std::string temp;
69+ for (unsigned int i = 0 ; i < len && iss.good (); ++i)
70+ temp.append (1 , iss.get ());
71+
72+ results.push_back (temp);
73+ if (results.size () == 3 )
74+ break ;
75+ }
76+
77+ _id = results[0 ];
78+ _severity = results[1 ];
79+ _msg = results[2 ];
80+
81+ unsigned int stackSize = 0 ;
82+ if (!(iss >> stackSize))
83+ return false ;
84+
85+ while (iss.good ())
86+ {
87+ unsigned int len = 0 ;
88+ if (!(iss >> len))
89+ return false ;
90+
91+ iss.get ();
92+ std::string temp;
93+ for (unsigned int i = 0 ; i < len && iss.good (); ++i)
94+ temp.append (1 , iss.get ());
95+
96+ ErrorLogger::ErrorMessage::FileLocation loc;
97+ loc.file = temp.substr (temp.find (' :' ) + 1 );
98+ temp = temp.substr (0 , temp.find (' :' ));
99+ std::istringstream fiss (temp);
100+ fiss >> loc.line ;
101+
102+ _callStack.push_back (loc);
103+
104+ if (_callStack.size () >= stackSize)
105+ break ;
106+ }
107+
108+ return true ;
109+ }
110+
34111std::string ErrorLogger::ErrorMessage::toXML () const
35112{
36113 std::ostringstream xml;
0 commit comments