PlatformUtils.hpp
Go to the documentation of this file.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id$
*/
#if !defined(XERCESC_INCLUDE_GUARD_PLATFORMUTILS_HPP)
#define XERCESC_INCLUDE_GUARD_PLATFORMUTILS_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLException.hpp>
#include <xercesc/util/PanicHandler.hpp>
#include <xercesc/util/XMLFileMgr.hpp>
#include <xercesc/util/XMLMutexMgr.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLMsgLoader;
class XMLNetAccessor;
class XMLTransService;
class MemoryManager;
class XMLMutex;
//
// For internal use only
//
// This class provides a simple abstract API via which lazily evaluated
// data can be cleaned up.
//
class XMLUTIL_EXPORT XMLDeleter
{
public :
virtual ~XMLDeleter();
protected :
XMLDeleter();
private :
XMLDeleter(const XMLDeleter&);
XMLDeleter& operator=(const XMLDeleter&);
};
class XMLUTIL_EXPORT XMLPlatformUtils
{
public :
static XMLNetAccessor* fgNetAccessor;
static XMLTransService* fgTransService;
#ifdef OS390
static XMLTransService* fgTransService2;
#endif
static PanicHandler* fgUserPanicHandler;
static PanicHandler* fgDefaultPanicHandler;
static MemoryManager* fgMemoryManager;
static XMLFileMgr* fgFileMgr;
static XMLMutexMgr* fgMutexMgr;
static XMLMutex* fgAtomicMutex;
static bool fgXMLChBigEndian;
static bool fgSSE2ok;
static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
, const char* const nlsHome = 0
, PanicHandler* const panicHandler = 0
, MemoryManager* const memoryManager = 0);
static void Initialize(XMLSize_t initialDOMHeapAllocSize
, XMLSize_t maxDOMHeapAllocSize
, XMLSize_t maxDOMSubAllocationSize
, const char* const locale = XMLUni::fgXercescDefaultLocale
, const char* const nlsHome = 0
, PanicHandler* const panicHandler = 0
, MemoryManager* const memoryManager = 0);
static void Terminate();
static void panic
(
const PanicHandler::PanicReasons reason
);
static XMLFileMgr* makeFileMgr(MemoryManager* const manager);
static XMLFilePos curFilePos(FileHandle theFile
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static void closeFile(FileHandle theFile
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static XMLFilePos fileSize(FileHandle theFile
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static FileHandle openFile(const char* const fileName
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static FileHandle openFile(const XMLCh* const fileName
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static FileHandle openFileToWrite(const char* const fileName
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static FileHandle openFileToWrite(const XMLCh* const fileName
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static XMLSize_t readFileBuffer
(
FileHandle theFile
, const XMLSize_t toRead
, XMLByte* const toFill
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
static void writeBufferToFile
(
FileHandle const theFile
, XMLSize_t toWrite
, const XMLByte* const toFlush
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
static void resetFile(FileHandle theFile
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static XMLCh* getFullPath
(
const XMLCh* const srcPath
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
static XMLCh* getCurrentDirectory
(
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
static inline bool isAnySlash(XMLCh c);
static void removeDotSlash(XMLCh* const srcPath
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static void removeDotDotSlash(XMLCh* const srcPath
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static bool isRelative(const XMLCh* const toCheck
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
static XMLCh* weavePaths
(
const XMLCh* const basePath
, const XMLCh* const relativePath
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
static unsigned long getCurrentMillis();
static XMLMutexMgr* makeMutexMgr(MemoryManager* const manager);
static void closeMutex(void* const mtxHandle, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static void lockMutex(void* const mtxHandle);
static void* makeMutex(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static void unlockMutex(void* const mtxHandle);
static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
static void recognizeNEL(bool state
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static bool isNELRecognized();
static void strictIANAEncoding(const bool state);
static bool isStrictIANAEncoding();
static inline XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize);
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XMLPlatformUtils();
static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
static XMLNetAccessor* makeNetAccessor();
static XMLTransService* makeTransService();
static int searchSlashDotDotSlash(XMLCh* const srcPath);
static bool fgMemMgrAdopted;
};
MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT)
// ---------------------------------------------------------------------------
// XMLPlatformUtils: alignPointerForNewBlockAllocation
// ---------------------------------------------------------------------------
// Calculate alignment required by platform for a new
// block allocation. We use this in our custom allocators
// to ensure that returned blocks are properly aligned.
// Note that, although this will take a pointer and return the position
// at which it should be placed for correct alignment, in our code
// we normally use XMLSize_t parameters to discover what the alignment
// of header blocks should be. Thus, if this is to be
// used for the former purpose, to make compilers happy
// some casting will be necessary - neilg.
//
// Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
// per-architecture basis to dictate the alignment requirements
// of the architecture. In the absense of this specification,
// this routine guesses at the correct alignment value.
//
// A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
// If a platform requires absolutely no alignment, a value
// of 1 should be specified ("align pointers on 1 byte boundaries").
//
inline XMLSize_t
XMLPlatformUtils::alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
{
// Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
// as needed to dictate alignment requirements on a
// per-architecture basis. In the absense of that we
// take an educated guess.
#ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
const XMLSize_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
#else
const XMLSize_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
#endif
// Calculate current alignment of pointer
XMLSize_t current = ptrSize % alignment;
// Adjust pointer alignment as needed
return (current == 0)
? ptrSize
: (ptrSize + alignment - current);
}
// ---------------------------------------------------------------------------
// XMLDeleter: Public Destructor
// ---------------------------------------------------------------------------
inline XMLDeleter::~XMLDeleter()
{
}
// ---------------------------------------------------------------------------
// XMLDeleter: Hidden constructors and operators
// ---------------------------------------------------------------------------
inline XMLDeleter::XMLDeleter()
{
}
XERCES_CPP_NAMESPACE_END
#endif
PanicHandler.hpp
XMLException.hpp
MakeXMLException
#define MakeXMLException(theType, expKeyword)
Definition XMLException.hpp:178
XMLFileMgr.hpp
FileHandle
XERCES_CPP_NAMESPACE_BEGIN typedef void * FileHandle
Definition XMLFileMgr.hpp:30
XMLMutexMgr.hpp
XercesDefs.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition XercesDefs.hpp:112
XMLByte
unsigned char XMLByte
Definition XercesDefs.hpp:65
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition XercesDefs.hpp:113
XMLCh
uint16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
XMLSize_t
size_t XMLSize_t
Definition Xerces_autoconf_config.hpp:112
XMLFilePos
XMLUInt64 XMLFilePos
Definition Xerces_autoconf_config.hpp:139
MemoryManager
Configurable memory manager.
Definition MemoryManager.hpp:40
PanicHandler
Receive notification of panic.
Definition PanicHandler.hpp:45
PanicHandler::PanicReasons
PanicReasons
Definition PanicHandler.hpp:51
XMLDeleter
Definition PlatformUtils.hpp:47
XMLDeleter::~XMLDeleter
virtual ~XMLDeleter()
Definition PlatformUtils.hpp:826
XMLDeleter::XMLDeleter
XMLDeleter()
Definition PlatformUtils.hpp:833
XMLFileMgr
Definition XMLFileMgr.hpp:35
XMLMutexMgr
Definition XMLMutexMgr.hpp:34
XMLNetAccessor
Definition XMLNetAccessor.hpp:96
XMLPlatformUtils
Utilities that must be implemented in a platform-specific way.
Definition PlatformUtils.hpp:69
XMLPlatformUtils::loadMsgSet
static XMLMsgLoader * loadMsgSet(const XMLCh *const msgDomain)
Loads the message set from among the available domains.
XMLPlatformUtils::fgFileMgr
static XMLFileMgr * fgFileMgr
Definition PlatformUtils.hpp:123
XMLPlatformUtils::lockMutex
static void lockMutex(void *const mtxHandle)
Locks a mutex handle.
XMLPlatformUtils::removeDotDotSlash
static void removeDotDotSlash(XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Remove occurrences of the dot dot slash.
XMLPlatformUtils::getCurrentDirectory
static XMLCh * getCurrentDirectory(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Gets the current working directory.
XMLPlatformUtils::readFileBuffer
static XMLSize_t readFileBuffer(FileHandle theFile, const XMLSize_t toRead, XMLByte *const toFill, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Reads the file buffer.
XMLPlatformUtils::fgMutexMgr
static XMLMutexMgr * fgMutexMgr
Definition PlatformUtils.hpp:124
XMLPlatformUtils::curFilePos
static XMLFilePos curFilePos(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get the current file position.
XMLPlatformUtils::makeMutexMgr
static XMLMutexMgr * makeMutexMgr(MemoryManager *const manager)
Factory method for creating MutexMgr object.
XMLPlatformUtils::Initialize
static void Initialize(XMLSize_t initialDOMHeapAllocSize, XMLSize_t maxDOMHeapAllocSize, XMLSize_t maxDOMSubAllocationSize, const char *const locale=XMLUni::fgXercescDefaultLocale, const char *const nlsHome=0, PanicHandler *const panicHandler=0, MemoryManager *const memoryManager=0)
Perform per-process parser initialization.
XMLPlatformUtils::isAnySlash
static bool isAnySlash(XMLCh c)
Check if a character is a slash.
XMLPlatformUtils::resetFile
static void resetFile(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Resets the file handle.
XMLPlatformUtils::closeMutex
static void closeMutex(void *const mtxHandle, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Closes a mutex handle.
XMLPlatformUtils::fgSSE2ok
static bool fgSSE2ok
Definition PlatformUtils.hpp:135
XMLPlatformUtils::isNELRecognized
static bool isNELRecognized()
Return the value of fgNEL flag.
XMLPlatformUtils::strictIANAEncoding
static void strictIANAEncoding(const bool state)
This function enables/disables strict IANA encoding names checking.
XMLPlatformUtils::getCurrentMillis
static unsigned long getCurrentMillis()
Gets the system time in milliseconds.
XMLPlatformUtils::alignPointerForNewBlockAllocation
static XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
Aligns the specified pointer per platform block allocation requirements.
XMLPlatformUtils::openFile
static FileHandle openFile(const XMLCh *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens a named file.
XMLPlatformUtils::openFileToWrite
static FileHandle openFileToWrite(const char *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Open a named file to write.
XMLPlatformUtils::fgXMLChBigEndian
static bool fgXMLChBigEndian
Definition PlatformUtils.hpp:134
XMLPlatformUtils::openStdInHandle
static FileHandle openStdInHandle(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens the standard input as a file.
XMLPlatformUtils::fgNetAccessor
static XMLNetAccessor * fgNetAccessor
The network accessor.
Definition PlatformUtils.hpp:87
XMLPlatformUtils::writeBufferToFile
static void writeBufferToFile(FileHandle const theFile, XMLSize_t toWrite, const XMLByte *const toFlush, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Writes the buffer to the file.
XMLPlatformUtils::openFileToWrite
static FileHandle openFileToWrite(const XMLCh *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Open a named file to write.
XMLPlatformUtils::fileSize
static XMLFilePos fileSize(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Returns the file size.
XMLPlatformUtils::isRelative
static bool isRelative(const XMLCh *const toCheck, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Determines if a path is relative or absolute.
XMLPlatformUtils::recognizeNEL
static void recognizeNEL(bool state, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
This function enables the recognition of NEL(0x85) char and LSEP (0x2028) as newline chars which is d...
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition PlatformUtils.hpp:121
XMLPlatformUtils::openFile
static FileHandle openFile(const char *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens the file.
XMLPlatformUtils::isStrictIANAEncoding
static bool isStrictIANAEncoding()
Returns whether a strict IANA encoding name check is enabled or disabled.
XMLPlatformUtils::closeFile
static void closeFile(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Closes the file handle.
XMLPlatformUtils::getFullPath
static XMLCh * getFullPath(const XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Gets the full path from a relative path.
XMLPlatformUtils::fgAtomicMutex
static XMLMutex * fgAtomicMutex
Global mutex for fast or infrequent operations.
Definition PlatformUtils.hpp:132
XMLPlatformUtils::Initialize
static void Initialize(const char *const locale=XMLUni::fgXercescDefaultLocale, const char *const nlsHome=0, PanicHandler *const panicHandler=0, MemoryManager *const memoryManager=0)
Perform per-process parser initialization.
XMLPlatformUtils::fgUserPanicHandler
static PanicHandler * fgUserPanicHandler
The Panic Handler.
Definition PlatformUtils.hpp:108
XMLPlatformUtils::panic
static void panic(const PanicHandler::PanicReasons reason)
The panic mechanism.
XMLPlatformUtils::weavePaths
static XMLCh * weavePaths(const XMLCh *const basePath, const XMLCh *const relativePath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Utility to join two paths.
XMLPlatformUtils::fgTransService
static XMLTransService * fgTransService
The transcoding service.
Definition PlatformUtils.hpp:99
XMLPlatformUtils::makeFileMgr
static XMLFileMgr * makeFileMgr(MemoryManager *const manager)
Make a new file object appropriate for the platform.
XMLPlatformUtils::fgDefaultPanicHandler
static PanicHandler * fgDefaultPanicHandler
The Panic Handler.
Definition PlatformUtils.hpp:114
XMLPlatformUtils::Terminate
static void Terminate()
Perform per-process parser termination.
XMLPlatformUtils::unlockMutex
static void unlockMutex(void *const mtxHandle)
Unlocks a mutex.
XMLPlatformUtils::makeMutex
static void * makeMutex(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Make a new mutex.
XMLPlatformUtils::removeDotSlash
static void removeDotSlash(XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Remove occurrences of the pair of dot slash.
XMLTransService
Definition TransService.hpp:53
XMLUni::fgXercescDefaultLocale
static const char fgXercescDefaultLocale[]
Definition XMLUni.hpp:305