~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/cxx/cxx_except.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1997-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#include "db_config.h"
9
 
 
10
 
#ifndef lint
11
 
static const char revid[] = "$Id$";
12
 
#endif /* not lint */
13
 
 
14
 
#include <string.h>
15
 
#include <errno.h>
16
 
 
17
 
#include "db_cxx.h"
18
 
#include "dbinc/cxx_int.h"
19
 
 
20
 
// tmpString is used to create strings on the stack
21
 
//
22
 
class tmpString
23
 
{
24
 
public:
25
 
        tmpString(const char *str1,
26
 
                  const char *str2 = 0,
27
 
                  const char *str3 = 0,
28
 
                  const char *str4 = 0,
29
 
                  const char *str5 = 0);
30
 
        ~tmpString()                      { delete [] s_; }
31
 
        operator const char *()           { return (s_); }
32
 
 
33
 
private:
34
 
        char *s_;
35
 
};
36
 
 
37
 
tmpString::tmpString(const char *str1,
38
 
                     const char *str2,
39
 
                     const char *str3,
40
 
                     const char *str4,
41
 
                     const char *str5)
42
 
{
43
 
        size_t len = strlen(str1);
44
 
        if (str2)
45
 
                len += strlen(str2);
46
 
        if (str3)
47
 
                len += strlen(str3);
48
 
        if (str4)
49
 
                len += strlen(str4);
50
 
        if (str5)
51
 
                len += strlen(str5);
52
 
 
53
 
        s_ = new char[len+1];
54
 
 
55
 
        strcpy(s_, str1);
56
 
        if (str2)
57
 
                strcat(s_, str2);
58
 
        if (str3)
59
 
                strcat(s_, str3);
60
 
        if (str4)
61
 
                strcat(s_, str4);
62
 
        if (str5)
63
 
                strcat(s_, str5);
64
 
}
65
 
 
66
 
// Note: would not be needed if we can inherit from exception
67
 
// It does not appear to be possible to inherit from exception
68
 
// with the current Microsoft library (VC5.0).
69
 
//
70
 
static char *dupString(const char *s)
71
 
{
72
 
        char *r = new char[strlen(s)+1];
73
 
        strcpy(r, s);
74
 
        return (r);
75
 
}
76
 
 
77
 
////////////////////////////////////////////////////////////////////////
78
 
//                                                                    //
79
 
//                            DbException                             //
80
 
//                                                                    //
81
 
////////////////////////////////////////////////////////////////////////
82
 
 
83
 
DbException::~DbException()
84
 
{
85
 
        if (what_)
86
 
                delete [] what_;
87
 
}
88
 
 
89
 
DbException::DbException(int err)
90
 
:       err_(err)
91
 
{
92
 
        what_ = dupString(db_strerror(err));
93
 
}
94
 
 
95
 
DbException::DbException(const char *description)
96
 
:       err_(0)
97
 
{
98
 
        what_ = dupString(tmpString(description));
99
 
}
100
 
 
101
 
DbException::DbException(const char *prefix, int err)
102
 
:       err_(err)
103
 
{
104
 
        what_ = dupString(tmpString(prefix, ": ", db_strerror(err)));
105
 
}
106
 
 
107
 
DbException::DbException(const char *prefix1, const char *prefix2, int err)
108
 
:       err_(err)
109
 
{
110
 
        what_ = dupString(tmpString(prefix1, ": ", prefix2, ": ",
111
 
            db_strerror(err)));
112
 
}
113
 
 
114
 
DbException::DbException(const DbException &that)
115
 
:       err_(that.err_)
116
 
{
117
 
        what_ = dupString(that.what_);
118
 
}
119
 
 
120
 
DbException &DbException::operator = (const DbException &that)
121
 
{
122
 
        if (this != &that) {
123
 
                err_ = that.err_;
124
 
                if (what_)
125
 
                        delete [] what_;
126
 
                what_ = 0;           // in case new throws exception
127
 
                what_ = dupString(that.what_);
128
 
        }
129
 
        return (*this);
130
 
}
131
 
 
132
 
int DbException::get_errno() const
133
 
{
134
 
        return (err_);
135
 
}
136
 
 
137
 
const char *DbException::what() const
138
 
{
139
 
        return (what_);
140
 
}
141
 
 
142
 
////////////////////////////////////////////////////////////////////////
143
 
//                                                                    //
144
 
//                            DbMemoryException                       //
145
 
//                                                                    //
146
 
////////////////////////////////////////////////////////////////////////
147
 
 
148
 
static const char *memory_err_desc = "Dbt not large enough for available data";
149
 
DbMemoryException::~DbMemoryException()
150
 
{
151
 
}
152
 
 
153
 
DbMemoryException::DbMemoryException(Dbt *dbt)
154
 
:       DbException(memory_err_desc, ENOMEM)
155
 
,       dbt_(dbt)
156
 
{
157
 
}
158
 
 
159
 
DbMemoryException::DbMemoryException(const char *description)
160
 
:       DbException(description, ENOMEM)
161
 
,       dbt_(0)
162
 
{
163
 
}
164
 
 
165
 
DbMemoryException::DbMemoryException(const char *prefix, Dbt *dbt)
166
 
:       DbException(prefix, memory_err_desc, ENOMEM)
167
 
,       dbt_(dbt)
168
 
{
169
 
}
170
 
 
171
 
DbMemoryException::DbMemoryException(const char *prefix1, const char *prefix2,
172
 
    Dbt *dbt)
173
 
:       DbException(prefix1, prefix2, ENOMEM)
174
 
,       dbt_(dbt)
175
 
{
176
 
}
177
 
 
178
 
DbMemoryException::DbMemoryException(const DbMemoryException &that)
179
 
:       DbException(that)
180
 
,       dbt_(that.dbt_)
181
 
{
182
 
}
183
 
 
184
 
DbMemoryException
185
 
&DbMemoryException::operator =(const DbMemoryException &that)
186
 
{
187
 
        if (this != &that) {
188
 
                DbException::operator=(that);
189
 
                dbt_ = that.dbt_;
190
 
        }
191
 
        return (*this);
192
 
}
193
 
 
194
 
Dbt *DbMemoryException::get_dbt() const
195
 
{
196
 
        return (dbt_);
197
 
}
198
 
 
199
 
////////////////////////////////////////////////////////////////////////
200
 
//                                                                    //
201
 
//                            DbDeadlockException                     //
202
 
//                                                                    //
203
 
////////////////////////////////////////////////////////////////////////
204
 
 
205
 
DbDeadlockException::~DbDeadlockException()
206
 
{
207
 
}
208
 
 
209
 
DbDeadlockException::DbDeadlockException(const char *description)
210
 
:       DbException(description, DB_LOCK_DEADLOCK)
211
 
{
212
 
}
213
 
 
214
 
DbDeadlockException::DbDeadlockException(const DbDeadlockException &that)
215
 
:       DbException(that)
216
 
{
217
 
}
218
 
 
219
 
DbDeadlockException
220
 
&DbDeadlockException::operator =(const DbDeadlockException &that)
221
 
{
222
 
        if (this != &that)
223
 
                DbException::operator=(that);
224
 
        return (*this);
225
 
}
226
 
 
227
 
////////////////////////////////////////////////////////////////////////
228
 
//                                                                    //
229
 
//                            DbLockNotGrantedException               //
230
 
//                                                                    //
231
 
////////////////////////////////////////////////////////////////////////
232
 
 
233
 
DbLockNotGrantedException::~DbLockNotGrantedException()
234
 
{
235
 
        delete lock_;
236
 
}
237
 
 
238
 
DbLockNotGrantedException::DbLockNotGrantedException(const char *prefix,
239
 
    db_lockop_t op, db_lockmode_t mode, const Dbt *obj, const DbLock lock,
240
 
    int index)
241
 
:       DbException(prefix, DbEnv::strerror(DB_LOCK_NOTGRANTED),
242
 
                    DB_LOCK_NOTGRANTED)
243
 
,       op_(op)
244
 
,       mode_(mode)
245
 
,       obj_(obj)
246
 
,       index_(index)
247
 
{
248
 
        lock_ = new DbLock(lock);
249
 
}
250
 
 
251
 
DbLockNotGrantedException::DbLockNotGrantedException
252
 
    (const DbLockNotGrantedException &that)
253
 
:       DbException(that)
254
 
{
255
 
        op_ = that.op_;
256
 
        mode_ = that.mode_;
257
 
        obj_ = that.obj_;
258
 
        lock_ = new DbLock(*that.lock_);
259
 
        index_ = that.index_;
260
 
}
261
 
 
262
 
DbLockNotGrantedException
263
 
&DbLockNotGrantedException::operator =(const DbLockNotGrantedException &that)
264
 
{
265
 
        if (this != &that) {
266
 
                DbException::operator=(that);
267
 
                op_ = that.op_;
268
 
                mode_ = that.mode_;
269
 
                obj_ = that.obj_;
270
 
                lock_ = new DbLock(*that.lock_);
271
 
                index_ = that.index_;
272
 
        }
273
 
        return (*this);
274
 
}
275
 
 
276
 
db_lockop_t DbLockNotGrantedException::get_op() const
277
 
{
278
 
        return op_;
279
 
}
280
 
 
281
 
db_lockmode_t DbLockNotGrantedException::get_mode() const
282
 
{
283
 
        return mode_;
284
 
}
285
 
 
286
 
const Dbt* DbLockNotGrantedException::get_obj() const
287
 
{
288
 
        return obj_;
289
 
}
290
 
 
291
 
DbLock* DbLockNotGrantedException::get_lock() const
292
 
{
293
 
        return lock_;
294
 
}
295
 
 
296
 
int DbLockNotGrantedException::get_index() const
297
 
{
298
 
        return index_;
299
 
}
300
 
 
301
 
 
302
 
 
303
 
////////////////////////////////////////////////////////////////////////
304
 
//                                                                    //
305
 
//                            DbRunRecoveryException                  //
306
 
//                                                                    //
307
 
////////////////////////////////////////////////////////////////////////
308
 
 
309
 
DbRunRecoveryException::~DbRunRecoveryException()
310
 
{
311
 
}
312
 
 
313
 
DbRunRecoveryException::DbRunRecoveryException(const char *description)
314
 
:       DbException(description, DB_RUNRECOVERY)
315
 
{
316
 
}
317
 
 
318
 
DbRunRecoveryException::DbRunRecoveryException
319
 
    (const DbRunRecoveryException &that)
320
 
:       DbException(that)
321
 
{
322
 
}
323
 
 
324
 
DbRunRecoveryException
325
 
&DbRunRecoveryException::operator =(const DbRunRecoveryException &that)
326
 
{
327
 
        if (this != &that)
328
 
                DbException::operator=(that);
329
 
        return (*this);
330
 
}