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: PlatformUtils.hpp 932889 2010-04-11 13:10:10Z borisk $
*/
#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
static const XMLSize_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
#else
static 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
XMLPlatformUtils::fgNetAccessor
static XMLNetAccessor * fgNetAccessor
The network accessor.
Definition: PlatformUtils.hpp:87
PanicHandler.hpp
XMLUni::fgXercescDefaultLocale
static const char fgXercescDefaultLocale[]
Definition: XMLUni.hpp:304
XMLMutexMgr
Definition: XMLMutexMgr.hpp:33
XMLPlatformUtils::fgSSE2ok
static bool fgSSE2ok
Definition: PlatformUtils.hpp:135
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLMutexMgr.hpp
XercesDefs.hpp
MakeXMLException
MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT) inline XMLSize_t XMLPlatformUtils
Definition: PlatformUtils.hpp:774
PanicHandler::PanicReasons
PanicReasons
Definition: PanicHandler.hpp:50
XMLPlatformUtils::fgAtomicMutex
static XMLMutex * fgAtomicMutex
Global mutex for fast or infrequent operations.
Definition: PlatformUtils.hpp:132
XMLFilePos
XMLUInt64 XMLFilePos
Definition: Xerces_autoconf_config.hpp:137
XMLNetAccessor
Definition: XMLNetAccessor.hpp:95
XMLException.hpp
XMLPlatformUtils::fgMutexMgr
static XMLMutexMgr * fgMutexMgr
Definition: PlatformUtils.hpp:124
XMLPlatformUtils::fgUserPanicHandler
static PanicHandler * fgUserPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:108
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:39
PanicHandler
Receive notification of panic.
Definition: PanicHandler.hpp:44
XMLPlatformUtils::fgDefaultPanicHandler
static PanicHandler * fgDefaultPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:114
XMLPlatformUtils::alignPointerForNewBlockAllocation
static XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
Aligns the specified pointer per platform block allocation requirements.
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:118
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLPlatformUtils
Utilities that must be implemented in a platform-specific way.
Definition: PlatformUtils.hpp:68
XMLPlatformUtils::fgXMLChBigEndian
static bool fgXMLChBigEndian
Definition: PlatformUtils.hpp:134
XMLTransService
Definition: TransService.hpp:52
XMLDeleter
Definition: PlatformUtils.hpp:46
FileHandle
XERCES_CPP_NAMESPACE_BEGIN typedef void * FileHandle
Definition: XMLFileMgr.hpp:30
XMLByte
unsigned char XMLByte
Definition: XercesDefs.hpp:65
XMLFileMgr
Definition: XMLFileMgr.hpp:34
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:110
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLPlatformUtils::fgTransService
static XMLTransService * fgTransService
The transcoding service.
Definition: PlatformUtils.hpp:99
XMLDeleter::~XMLDeleter
virtual ~XMLDeleter()
Definition: PlatformUtils.hpp:826
XMLFileMgr.hpp
XMLPlatformUtils::fgFileMgr
static XMLFileMgr * fgFileMgr
Definition: PlatformUtils.hpp:123
XMLDeleter::XMLDeleter
XMLDeleter()
Definition: PlatformUtils.hpp:833