| 1 |
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ |
| 2 |
|
| 3 |
/* AbiSource Program Utilities |
| 4 |
* |
| 5 |
* Copyright (C) 2002 Francis James Franklin <[email protected]> |
| 6 |
* Copyright (C) 2002 AbiSource, Inc. |
| 7 |
* |
| 8 |
* This program is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU General Public License |
| 10 |
* as published by the Free Software Foundation; either version 2 |
| 11 |
* of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program; if not, write to the Free Software |
| 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 |
* 02110-1301 USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef XAP_RESOURCE_MANAGER_H |
| 25 |
#define XAP_RESOURCE_MANAGER_H |
| 26 |
|
| 27 |
/* pre-emptive dismissal; ut_types.h is needed by just about everything, |
| 28 |
* so even if it's commented out in-file that's still a lot of work for |
| 29 |
* the preprocessor to do... |
| 30 |
*/ |
| 31 |
#ifndef UT_TYPES_H |
| 32 |
#include "ut_types.h" |
| 33 |
#endif |
| 34 |
|
| 35 |
#include "xap_Resource.h" |
| 36 |
|
| 37 |
class UT_UTF8String; |
| 38 |
|
| 39 |
class ABI_EXPORT XAP_ResourceManager |
| 40 |
{ |
| 41 |
public: |
| 42 |
XAP_ResourceManager (); |
| 43 |
|
| 44 |
~XAP_ResourceManager (); |
| 45 |
|
| 46 |
const UT_UTF8String new_id (bool bInternal = true); |
| 47 |
|
| 48 |
/* returns resource corresponding to href; sets m_current to the result |
| 49 |
* returns 0 if none is found |
| 50 |
*/ |
| 51 |
XAP_Resource * resource (const char * href, bool bInternal, UT_uint32 * index = 0); |
| 52 |
XAP_Resource * current () const |
| 53 |
{ |
| 54 |
return m_current; |
| 55 |
} |
| 56 |
void clear_current () |
| 57 |
{ |
| 58 |
m_current = 0; |
| 59 |
} |
| 60 |
|
| 61 |
/* resource objects are created/destroyed via ref/unref |
| 62 |
* ref() returns false if href is not, and cannot be, created |
| 63 |
*/ |
| 64 |
bool ref (const char * href); |
| 65 |
void unref (const char * href); |
| 66 |
|
| 67 |
/* number of internal resources |
| 68 |
*/ |
| 69 |
UT_uint32 count () const { return m_resource_count; } |
| 70 |
|
| 71 |
XAP_Resource * operator[] (UT_uint32 i) const |
| 72 |
{ |
| 73 |
return (i < m_resource_count) ? m_resource[i] : 0; |
| 74 |
} |
| 75 |
|
| 76 |
class ABI_EXPORT Writer : public XAP_InternalResource::Writer |
| 77 |
{ |
| 78 |
public: |
| 79 |
virtual ~Writer () { } |
| 80 |
|
| 81 |
/* start element |
| 82 |
*/ |
| 83 |
virtual UT_Error write_xml (void * context, const char * name, const char * const * atts) = 0; |
| 84 |
|
| 85 |
/* end element |
| 86 |
*/ |
| 87 |
virtual UT_Error write_xml (void * context, const char * name) = 0; |
| 88 |
}; |
| 89 |
|
| 90 |
UT_Error write_xml (void * context, Writer & writer); // call's writer's write_xml() & write_base64() callbacks |
| 91 |
|
| 92 |
private: |
| 93 |
XAP_Resource * m_current; // current resource |
| 94 |
|
| 95 |
XAP_Resource ** m_resource; |
| 96 |
|
| 97 |
UT_uint32 m_resource_count; |
| 98 |
UT_uint32 m_resource_max; |
| 99 |
|
| 100 |
UT_uint32 m_id_number; |
| 101 |
|
| 102 |
bool grow (); |
| 103 |
}; |
| 104 |
|
| 105 |
#endif /* ! XAP_RESOURCE_MANAGER_H */ |