summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmserializer.h
blob: 4c579364d127d9b462bb511d712b3410534b0d11 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//-*-C++-*-
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#ifndef PMSERIALIZER_H
#define PMSERIALIZER_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

class TQIODevice;

#include "pmobject.h"
#include "pmerrordialog.h"

#include <tqdict.h>


/**
 * Class to serialize an object or a list of objects.
 *
 * Normally you don't have to create instances of this type or subclasses,
 * the class @ref PMIOFormat has factory methods to create them.
 *
 * There is one sub class for each format.
 *
 * During serialization, errors can occur. These are returned
 * by the method @ref errors.
 */
class PMSerializer
{
public:
   /**
    * Default constructor
    *
    * The serialized data will be written to the io device
    */
   PMSerializer( TQIODevice* dev );
   /**
    * Destructor
    */
   virtual ~PMSerializer( );
   /**
    * Returns the translated description of the format. Should return
    * the same string as description( ) of the corresponding
    * IO format.
    */
   virtual TQString description( ) const = 0;

   /**
    * Serializes one object to the device
    */
   virtual void serialize( PMObject* o ) = 0;
   /**
    * Serializes a list of objects. The default
    * implementation will call serialize( PMObject* ) for each object.
    */
   virtual void serializeList( const PMObjectList& objects );
   /**
    * Closes the serializer
    */
   virtual void close( ) = 0;

   /**
    * Returns the messages of the serializer
    */
   PMMessageList messages( ) const { return m_messages; }
   /**
    * Returns true if there were errors during serializing
    */
   bool errors( ) const { return m_errors > 0; }
   /**
    * Returns true if there were warnings during serializing
    */
   bool warnings( ) const { return m_warnings > 0; }
   /**
    * Returns true, if a fatal error occurred
    * and it doesn't make sense to continue
    */
   bool fatal( ) const { return m_bFatalError; }
   /**
    * Returns a bitwise combination of @ref PMErrorFlags constants
    */
   int errorFlags( ) const;

   /**
    * Adds an error to the message string
    */
   void printError( const TQString& msg );
   /**
    * Adds a warning to the message string
    */
   void printWarning( const TQString& msg );
   /**
    * Adds an info to the message string
    */
   void printInfo( const TQString& msg );
   /**
    * Adds the message to the message string. Type is "error", "warning",
    * "info"
    */
   void printMessage( const TQString& type, const TQString& msg );

   /**
    * Sets the fatal error flag
    */
   void setFatalError( ) { m_bFatalError = true; }

   /**
    * returns the maximum number of errors
    */
   static unsigned maxErrors( ) { return s_maxErrors; }
   /**
    * sets the maximum number of errors to m
    */
   static void setMaxErrors( unsigned m ) { s_maxErrors = m; }
   /**
    * returns the maximum number of warnings
    */
   static unsigned maxWarnings( ) { return s_maxWarnings; }
   /**
    * sets the maximum number of warnings to m
    */
   static void setMaxWarnings( unsigned m ) { s_maxWarnings = m; }

protected:
   /**
    * The assigned IO device for serialization
    */
   TQIODevice* m_pDev;

private:
   /**
    * The serializer output (errors, warnings...)
    */
   PMMessageList m_messages;
   /**
    * A dictionary object -> message
    */
   TQPtrDict< TQPtrList<PMMessage> > m_messageDict;
   /**
    * Number of warnings during parsing
    */
   unsigned int m_warnings;
   /**
    * Number of errors during parsing
    */
   unsigned int m_errors;
   /**
    * Flag for fatal errors
    */
   bool m_bFatalError;

   /**
    * maximum number of errors
    */
   static unsigned int s_maxErrors;
   /**
    * maximum number of warnings
    */
   static unsigned int s_maxWarnings;
};

#endif