| 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_H |
| 25 |
#define XAP_RESOURCE_H |
| 26 |
|
| 27 |
#include "ut_string_class.h" |
| 28 |
|
| 29 |
class ABI_EXPORT XAP_Resource |
| 30 |
{ |
| 31 |
protected: |
| 32 |
XAP_Resource (const char * resource_name, bool resource_internal); |
| 33 |
|
| 34 |
public: |
| 35 |
virtual ~XAP_Resource () { } |
| 36 |
|
| 37 |
const UT_UTF8String & name () const { return m_resource_name; } |
| 38 |
|
| 39 |
UT_uint32 ref () { return ++m_ref_count; } |
| 40 |
UT_uint32 unref () { return m_ref_count ? --m_ref_count : 0; } |
| 41 |
|
| 42 |
UT_uint32 count () const { return m_ref_count; } |
| 43 |
|
| 44 |
const bool bInternal; |
| 45 |
|
| 46 |
UT_UTF8String Description; // Doesn't seem to be any point in hiding this... |
| 47 |
private: |
| 48 |
UT_UTF8String m_resource_name; |
| 49 |
|
| 50 |
UT_uint32 m_ref_count; |
| 51 |
}; |
| 52 |
|
| 53 |
class ABI_EXPORT XAP_InternalResource : public XAP_Resource |
| 54 |
{ |
| 55 |
public: |
| 56 |
class ABI_EXPORT Writer |
| 57 |
{ |
| 58 |
public: |
| 59 |
virtual ~Writer () { } |
| 60 |
|
| 61 |
virtual UT_Error write_base64 (void * context, const char * base64, UT_uint32 length, bool final) = 0; |
| 62 |
}; |
| 63 |
|
| 64 |
XAP_InternalResource (const char * resource_id); |
| 65 |
|
| 66 |
~XAP_InternalResource (); |
| 67 |
|
| 68 |
/* buffer containing binary representation |
| 69 |
* |
| 70 |
* returns 0 on mem-err or illegal base64 chars encountered; if base64_encoded then length will change |
| 71 |
*/ |
| 72 |
const char * buffer (const char * new_buffer, UT_uint32 new_buffer_length, bool base64_encoded = false); |
| 73 |
|
| 74 |
const char * buffer () const { return m_buffer; } |
| 75 |
UT_uint32 length () const { return m_buffer_length; } |
| 76 |
|
| 77 |
UT_Error write_base64 (void * context, Writer & writer); // call's writer's write_base64() callback |
| 78 |
|
| 79 |
const UT_UTF8String & type (const UT_UTF8String & new_content_type); |
| 80 |
const UT_UTF8String & type (const char * new_content_type); |
| 81 |
|
| 82 |
const UT_UTF8String & type () const { return m_content_type; } |
| 83 |
|
| 84 |
private: |
| 85 |
void clear (); |
| 86 |
|
| 87 |
char * m_buffer; |
| 88 |
UT_uint32 m_buffer_length; |
| 89 |
|
| 90 |
UT_UTF8String m_content_type; |
| 91 |
}; |
| 92 |
|
| 93 |
class ABI_EXPORT XAP_ExternalResource : public XAP_Resource |
| 94 |
{ |
| 95 |
public: |
| 96 |
XAP_ExternalResource (const char * resource_id); |
| 97 |
|
| 98 |
~XAP_ExternalResource (); |
| 99 |
|
| 100 |
const UT_UTF8String & URL () const |
| 101 |
{ |
| 102 |
return m_url; |
| 103 |
} |
| 104 |
const UT_UTF8String & URL (const UT_UTF8String & url); |
| 105 |
|
| 106 |
private: |
| 107 |
UT_UTF8String m_url; |
| 108 |
}; |
| 109 |
|
| 110 |
#endif /* ! XAP_RESOURCE_H */ |