• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xap_ResourceManager.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiSource Program Utilities
00004  *
00005  * Copyright (C) 2002 Francis James Franklin <fjf@alinameridon.com>
00006  * Copyright (C) 2002 AbiSource, Inc.
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00021  * 02110-1301 USA.
00022  */
00023 
00024 #ifndef XAP_RESOURCE_MANAGER_H
00025 #define XAP_RESOURCE_MANAGER_H
00026 
00027 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00028  * so even if it's commented out in-file that's still a lot of work for
00029  * the preprocessor to do...
00030  */
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034 
00035 #include "xap_Resource.h"
00036 
00037 class UT_UTF8String;
00038 
00039 class ABI_EXPORT XAP_ResourceManager
00040 {
00041 public:
00042     XAP_ResourceManager ();
00043 
00044     ~XAP_ResourceManager ();
00045 
00046     const UT_UTF8String new_id (bool bInternal = true);
00047 
00048     /* returns resource corresponding to href; sets m_current to the result
00049      * returns 0 if none is found
00050      */
00051     XAP_Resource * resource (const char * href, bool bInternal, UT_uint32 * index = 0);
00052     XAP_Resource * current () const
00053     {
00054         return m_current;
00055     }
00056     void clear_current ()
00057     {
00058         m_current = 0;
00059     }
00060 
00061     /* resource objects are created/destroyed via ref/unref
00062      * ref() returns false if href is not, and cannot be, created
00063      */
00064     bool ref (const char * href);
00065     void unref (const char * href);
00066 
00067     /* number of internal resources
00068      */
00069     UT_uint32 count () const { return m_resource_count; }
00070 
00071     XAP_Resource * operator[] (UT_uint32 i) const
00072     {
00073         return (i < m_resource_count) ? m_resource[i] : 0;
00074     }
00075 
00076     class ABI_EXPORT Writer : public XAP_InternalResource::Writer
00077     {
00078     public:
00079         virtual ~Writer () { }
00080 
00081         /* start element
00082          */
00083         virtual UT_Error write_xml (void * context, const char * name, const char * const * atts) = 0;
00084 
00085         /* end element
00086          */
00087         virtual UT_Error write_xml (void * context, const char * name) = 0;
00088     };
00089 
00090     UT_Error write_xml (void * context, Writer & writer); // call's writer's write_xml() & write_base64() callbacks
00091 
00092 private:
00093     XAP_Resource * m_current; // current resource
00094 
00095     XAP_Resource ** m_resource;
00096 
00097     UT_uint32 m_resource_count;
00098     UT_uint32 m_resource_max;
00099 
00100     UT_uint32 m_id_number;
00101 
00102     bool grow ();
00103 };
00104 
00105 #endif /* ! XAP_RESOURCE_MANAGER_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1