| 1 | cycrow | 1 | /*
 | 
        
           |  |  | 2 |   this is the main class of the encoder/decoder
 | 
        
           |  |  | 3 |   it has all the methods you need to load/write/convert the bob/bod data
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 |   I was inspired by document object model (DOM) from W3C - hence the 
 | 
        
           |  |  | 6 |   bob_dom prefix in most of classes
 | 
        
           |  |  | 7 | */
 | 
        
           |  |  | 8 |   | 
        
           |  |  | 9 | #ifndef BOB_DOM_INCLUDED
 | 
        
           |  |  | 10 | #define BOB_DOM_INCLUDED
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 | #include "bob_dom_cut.h"
 | 
        
           |  |  | 13 | #include "bob_dom_bob.h"
 | 
        
           |  |  | 14 |   | 
        
           |  |  | 15 | #include "settings.h"
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | #include <stdarg.h>
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | class bob_dom_document
 | 
        
           |  |  | 20 | {
 | 
        
           |  |  | 21 | 	public:
 | 
        
           |  |  | 22 | 		enum ErrorCode
 | 
        
           |  |  | 23 | 		{
 | 
        
           |  |  | 24 | 			// BOB converter
 | 
        
           |  |  | 25 | 			E_BadHeader,
 | 
        
           |  |  | 26 | 			E_BadEndHeader,
 | 
        
           |  |  | 27 | 			E_Error,
 | 
        
           |  |  | 28 | 			E_NoError,
 | 
        
           |  |  | 29 | 			E_MoreData,
 | 
        
           |  |  | 30 | 			E_NotEnoughData,
 | 
        
           |  |  | 31 | 			E_NoStatFormat,
 | 
        
           |  |  | 32 | 			E_FormatUserWarning,
 | 
        
           |  |  | 33 | 			E_UnkPointHeader,
 | 
        
           |  |  | 34 | 			E_PointNotFound,
 | 
        
           |  |  | 35 | 			E_BadVersion
 | 
        
           |  |  | 36 | 		};
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 | 		enum ErrorSeverity
 | 
        
           |  |  | 39 | 		{
 | 
        
           |  |  | 40 | 			BOB_OK,
 | 
        
           |  |  | 41 | 			S_Warning,
 | 
        
           |  |  | 42 | 			S_Error
 | 
        
           |  |  | 43 | 		};
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 | 		enum ErrorFacility
 | 
        
           |  |  | 46 | 		{
 | 
        
           |  |  | 47 | 			F_BOBLoader,
 | 
        
           |  |  | 48 | 			F_StatLoader
 | 
        
           |  |  | 49 | 		};
 | 
        
           |  |  | 50 |   | 
        
           |  |  | 51 | 		struct Error
 | 
        
           |  |  | 52 | 		{
 | 
        
           |  |  | 53 | 			int code;
 | 
        
           |  |  | 54 | 			char text[255];
 | 
        
           |  |  | 55 |   | 
        
           |  |  | 56 | 			void makeCode(ErrorFacility f, ErrorSeverity s, ErrorCode e)
 | 
        
           |  |  | 57 | 			{
 | 
        
           |  |  | 58 | 				code=s << 24;
 | 
        
           |  |  | 59 | 				code|=f << 16;
 | 
        
           |  |  | 60 | 				code|=e;
 | 
        
           |  |  | 61 | 			}
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 | 			ErrorSeverity severity() const { return (ErrorSeverity)(code >> 24); }
 | 
        
           |  |  | 64 | 			ErrorFacility facility() const { return (ErrorFacility)((code >> 16) & 0xff); }
 | 
        
           |  |  | 65 | 			bool failed() const { return (severity() & S_Error) > 0; }
 | 
        
           |  |  | 66 | 			bool warning() const { return (severity() & S_Warning) > 0; }
 | 
        
           |  |  | 67 | 			bool succeeded() const { return (severity() & BOB_OK) == 0; }
 | 
        
           |  |  | 68 |   | 
        
           |  |  | 69 | 			ErrorCode getCode() const { return (ErrorCode)(code & 0xFFFF); }
 | 
        
           |  |  | 70 | 		};
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 | 	private:
 | 
        
           |  |  | 73 | 		typedef ext::list<Error*> ErrorList;
 | 
        
           |  |  | 74 |   | 
        
           |  |  | 75 | 		const Settings *settings;
 | 
        
           |  |  | 76 |   | 
        
           |  |  | 77 | 		void error(ErrorFacility facility, ErrorSeverity severity, ErrorCode code, const char *format, ...);
 | 
        
           |  |  | 78 | 		void verror(ErrorFacility facility, ErrorSeverity severity, ErrorCode code, const char *format, va_list ap);
 | 
        
           |  |  | 79 | 		void vbob_error(bob_error_severity severity, bob_error_codes code, const char *format, va_list ap);
 | 
        
           |  |  | 80 | 		void bob_error(bob_error_severity severity, bob_error_codes code, const char *format, ...);
 | 
        
           |  |  | 81 | 		void ini_error(Settings::ErrorType type, Settings::ErrorCodes code, const char *msg);
 | 
        
           |  |  | 82 |   | 
        
           |  |  | 83 | 	public:
 | 
        
           |  |  | 84 | 		typedef ErrorList::iterator ErrorIterator;
 | 
        
           |  |  | 85 |   | 
        
           |  |  | 86 | 		bob_dom_bob *bob;
 | 
        
           |  |  | 87 | 		bob_dom_cut *cut;
 | 
        
           |  |  | 88 | 		ErrorList errors;
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 | 		bob_dom_document(const Settings *settings) { this->settings=settings; bob=0; cut=0; }
 | 
        
           |  |  | 91 | 		~bob_dom_document() { delete bob; delete cut; clearErrors(); }
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 | 		void clearErrors() 
 | 
        
           |  |  | 94 | 		{ 
 | 
        
           |  |  | 95 | 			for(ErrorIterator &it=errors.begin(); it!=errors.end(); ++it){
 | 
        
           |  |  | 96 | 				delete *it;
 | 
        
           |  |  | 97 | 			}
 | 
        
           |  |  | 98 | 			errors.clear(); 
 | 
        
           |  |  | 99 | 		}
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 | 		bool fromFile(bob_dom_ibinaryfilestream& is);
 | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 | 		bool convert(bob_dom_ibinaryfilestream& is, bob_dom_otextfilestream& os);
 | 
        
           |  |  | 104 |   | 
        
           |  |  | 105 | 		bool toFile(bob_dom_obinaryfilestream& os);
 | 
        
           |  |  | 106 | 		bool toFile(bob_dom_otextfilestream& os);
 | 
        
           |  |  | 107 |   | 
        
           |  |  | 108 | };
 | 
        
           |  |  | 109 |   | 
        
           |  |  | 110 |   | 
        
           |  |  | 111 | #endif // !defined(BOB_DOM_INCLUDED)
 |