1
0
forked from 0ad/0ad
0ad/source/ps/XML/Xeromyces.h
janwas a859562ea7 improvements and fixes:
- properly differentiate between buffer/offset alignment and length
alignment (relevant since block size has been increased to 256k)
- use VfsPath for most game paths instead of CStr
- clean up timer interface and implementation
- self-tests no longer crash
- file_cache.cpp: fix for the case where allocation fails (prevent
deleter from seeing a null pointer)
- allocators: move all shared_ptr-related stuff to its own component;
add DummySharedPtr
- codec: disable checksums (important for performance at work)
- File: made into an interface class to avoid export problems. not
entirely sure about this..
- vfs_path.h, path.h, os_path.h: proper fix for using
fs::change_extension and similar utility functions with derivatives of
basic_path
- lib_api: automatically link against import lib if building lib/ as a
DLL
- path_util: remove unused functions (this component is deprecated)
- compiler.h: add INLINE
- Xeromyces.cpp: pass PIVFS so that GetXMBPath works in self-test
(should do this mostly everywhere rather than have one singleton g_VFS)

This was SVN commit r5537.
2008-01-07 20:03:19 +00:00

67 lines
1.8 KiB
C++

/*
Xeromyces file-loading interface.
Automatically creates and caches relatively
efficient binary representations of XML files.
*/
#ifndef INCLUDED_XEROMYCES
#define INCLUDED_XEROMYCES
#include "ps/Errors.h"
ERROR_GROUP(Xeromyces);
ERROR_TYPE(Xeromyces, XMLOpenFailed);
ERROR_TYPE(Xeromyces, XMLParseError);
#include "XeroXMB.h"
#include "ps/Filesystem.h"
class CXeromyces : public XMBFile
{
friend class TestXeromyces;
public:
CXeromyces();
~CXeromyces();
// Load from an XML file (with invisible XMB caching).
PSRETURN Load(const VfsPath& filename);
// Call once when shutting down the program, to unload Xerces.
static void Terminate();
private:
// Find out write location of the XMB file corresponding to xmlFilename
static void GetXMBPath(PIVFS vfs, const VfsPath& xmlFilename, const VfsPath& xmbFilename, VfsPath& xmbActualPath);
bool ReadXMBFile(const VfsPath& filename);
shared_ptr<u8> XMBBuffer;
static int XercesLoaded; // for once-only initialisation
};
#define _XERO_MAKE_UID2__(p,l) p ## l
#define _XERO_MAKE_UID1__(p,l) _XERO_MAKE_UID2__(p,l)
#define _XERO_CHILDREN _XERO_MAKE_UID1__(_children_, __LINE__)
#define _XERO_I _XERO_MAKE_UID1__(_i_, __LINE__)
#define XERO_ITER_EL(parent_element, child_element) \
XMBElementList _XERO_CHILDREN = parent_element.GetChildNodes(); \
XMBElement child_element (0); \
for (int _XERO_I = 0; \
_XERO_I < _XERO_CHILDREN.Count \
&& (child_element = _XERO_CHILDREN.Item(_XERO_I), 1); \
++_XERO_I)
#define XERO_ITER_ATTR(parent_element, attribute) \
XMBAttributeList _XERO_CHILDREN = parent_element.GetAttributes(); \
XMBAttribute attribute; \
for (int _XERO_I = 0; \
_XERO_I < _XERO_CHILDREN.Count \
&& (attribute = _XERO_CHILDREN.Item(_XERO_I), 1); \
++_XERO_I)
#endif // INCLUDED_XEROMYCES