Xerces-C++  3.2.3
PlatformUtils.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*
19  * $Id$
20  */
21 
22 #if !defined(XERCESC_INCLUDE_GUARD_PLATFORMUTILS_HPP)
23 #define XERCESC_INCLUDE_GUARD_PLATFORMUTILS_HPP
24 
28 
31 
33 
34 class XMLMsgLoader;
35 class XMLNetAccessor;
36 class XMLTransService;
37 class MemoryManager;
38 class XMLMutex;
39 
40 //
41 // For internal use only
42 //
43 // This class provides a simple abstract API via which lazily evaluated
44 // data can be cleaned up.
45 //
47 {
48 public :
49  virtual ~XMLDeleter();
50 
51 protected :
52  XMLDeleter();
53 
54 private :
55  XMLDeleter(const XMLDeleter&);
56  XMLDeleter& operator=(const XMLDeleter&);
57 };
58 
59 
69 {
70 public :
71 
74 
88 
100 #ifdef OS390
101  static XMLTransService* fgTransService2;
102 #endif
103 
109 
115 
122 
125 
132  static XMLMutex* fgAtomicMutex;
133 
134  static bool fgXMLChBigEndian;
135  static bool fgSSE2ok;
137 
138 
141 
173  static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
174  , const char* const nlsHome = 0
175  , PanicHandler* const panicHandler = 0
176  , MemoryManager* const memoryManager = 0);
177 
227  static void Initialize(XMLSize_t initialDOMHeapAllocSize
228  , XMLSize_t maxDOMHeapAllocSize
229  , XMLSize_t maxDOMSubAllocationSize
230  , const char* const locale = XMLUni::fgXercescDefaultLocale
231  , const char* const nlsHome = 0
232  , PanicHandler* const panicHandler = 0
233  , MemoryManager* const memoryManager = 0);
234 
241  static void Terminate();
242 
259  static void panic
260  (
261  const PanicHandler::PanicReasons reason
262  );
263 
265 
268 
273  static XMLFileMgr* makeFileMgr(MemoryManager* const manager);
274 
290 
301  static void closeFile(FileHandle theFile
303 
316 
327  static FileHandle openFile(const char* const fileName
329 
340  static FileHandle openFile(const XMLCh* const fileName
342 
353  static FileHandle openFileToWrite(const char* const fileName
355 
366  static FileHandle openFileToWrite(const XMLCh* const fileName
368 
380 
398  (
399  FileHandle theFile
400  , const XMLSize_t toRead
401  , XMLByte* const toFill
403  );
404 
419  static void writeBufferToFile
420  (
421  FileHandle const theFile
422  , XMLSize_t toWrite
423  , const XMLByte* const toFlush
425  );
426 
436  static void resetFile(FileHandle theFile
438 
440 
441 
466  (
467  const XMLCh* const srcPath
469  );
470 
485  (
487  );
488 
498  static inline bool isAnySlash(XMLCh c);
499 
509  static void removeDotSlash(XMLCh* const srcPath
511 
522  static void removeDotDotSlash(XMLCh* const srcPath
524 
538  static bool isRelative(const XMLCh* const toCheck
540  );
541 
562  (
563  const XMLCh* const basePath
564  , const XMLCh* const relativePath
566  );
568 
571 
581  static unsigned long getCurrentMillis();
583 
586 
594  static XMLMutexMgr* makeMutexMgr(MemoryManager* const manager);
595 
604  static void closeMutex(void* const mtxHandle, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
605 
613  static void lockMutex(void* const mtxHandle);
614 
625 
638  static void unlockMutex(void* const mtxHandle);
639 
641 
642 
645 
653  static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
654 
656 
657 
671  static void recognizeNEL(bool state
673 
677  static bool isNELRecognized();
679 
691  static void strictIANAEncoding(const bool state);
692 
697  static bool isStrictIANAEncoding();
699 
708 
709 private :
710  // -----------------------------------------------------------------------
711  // Unimplemented constructors and operators
712  // -----------------------------------------------------------------------
714 
717 
723  static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
724 
734  static XMLNetAccessor* makeNetAccessor();
735 
746  static XMLTransService* makeTransService();
747 
755  static int searchSlashDotDotSlash(XMLCh* const srcPath);
756 
758 
761 
768  static bool fgMemMgrAdopted;
769 
771 };
772 
773 
774 MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT)
775 
776 
777 // ---------------------------------------------------------------------------
778 // XMLPlatformUtils: alignPointerForNewBlockAllocation
779 // ---------------------------------------------------------------------------
780 // Calculate alignment required by platform for a new
781 // block allocation. We use this in our custom allocators
782 // to ensure that returned blocks are properly aligned.
783 // Note that, although this will take a pointer and return the position
784 // at which it should be placed for correct alignment, in our code
785 // we normally use XMLSize_t parameters to discover what the alignment
786 // of header blocks should be. Thus, if this is to be
787 // used for the former purpose, to make compilers happy
788 // some casting will be necessary - neilg.
789 //
790 // Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
791 // per-architecture basis to dictate the alignment requirements
792 // of the architecture. In the absense of this specification,
793 // this routine guesses at the correct alignment value.
794 //
795 // A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
796 // If a platform requires absolutely no alignment, a value
797 // of 1 should be specified ("align pointers on 1 byte boundaries").
798 //
799 inline XMLSize_t
801 {
802  // Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
803  // as needed to dictate alignment requirements on a
804  // per-architecture basis. In the absense of that we
805  // take an educated guess.
806 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
807  const XMLSize_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
808 #else
809  const XMLSize_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
810 #endif
811 
812  // Calculate current alignment of pointer
813  XMLSize_t current = ptrSize % alignment;
814 
815  // Adjust pointer alignment as needed
816  return (current == 0)
817  ? ptrSize
818  : (ptrSize + alignment - current);
819 }
820 
821 
822 
823 // ---------------------------------------------------------------------------
824 // XMLDeleter: Public Destructor
825 // ---------------------------------------------------------------------------
827 {
828 }
829 
830 // ---------------------------------------------------------------------------
831 // XMLDeleter: Hidden constructors and operators
832 // ---------------------------------------------------------------------------
834 {
835 }
836 
838 
839 #endif
MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT) inline XMLSize_t XMLPlatformUtils
Definition: PlatformUtils.hpp:774
XERCES_CPP_NAMESPACE_BEGIN typedef void * FileHandle
Definition: XMLFileMgr.hpp:30
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
unsigned char XMLByte
Definition: XercesDefs.hpp:65
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
char16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
XMLUInt64 XMLFilePos
Definition: Xerces_autoconf_config.hpp:139
Configurable memory manager.
Definition: MemoryManager.hpp:40
Receive notification of panic.
Definition: PanicHandler.hpp:45
PanicReasons
Definition: PanicHandler.hpp:51
Definition: PlatformUtils.hpp:47
virtual ~XMLDeleter()
Definition: PlatformUtils.hpp:826
XMLDeleter()
Definition: PlatformUtils.hpp:833
Definition: XMLFileMgr.hpp:35
Definition: XMLMutexMgr.hpp:34
Definition: XMLNetAccessor.hpp:96
Utilities that must be implemented in a platform-specific way.
Definition: PlatformUtils.hpp:69
static XMLFileMgr * makeFileMgr(MemoryManager *const manager)
Make a new file object appropriate for the platform.
static XMLFileMgr * fgFileMgr
Definition: PlatformUtils.hpp:123
static void lockMutex(void *const mtxHandle)
Locks a mutex handle.
static void removeDotDotSlash(XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Remove occurrences of the dot dot slash.
static XMLSize_t readFileBuffer(FileHandle theFile, const XMLSize_t toRead, XMLByte *const toFill, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Reads the file buffer.
static XMLMutexMgr * fgMutexMgr
Definition: PlatformUtils.hpp:124
static XMLFilePos curFilePos(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get the current file position.
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.
static bool isAnySlash(XMLCh c)
Check if a character is a slash.
static void resetFile(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Resets the file handle.
static void closeMutex(void *const mtxHandle, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Closes a mutex handle.
static bool fgSSE2ok
Definition: PlatformUtils.hpp:135
static XMLCh * getFullPath(const XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Gets the full path from a relative path.
static bool isNELRecognized()
Return the value of fgNEL flag.
static void strictIANAEncoding(const bool state)
This function enables/disables strict IANA encoding names checking.
static unsigned long getCurrentMillis()
Gets the system time in milliseconds.
static XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
Aligns the specified pointer per platform block allocation requirements.
static FileHandle openFile(const XMLCh *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens a named file.
static FileHandle openFileToWrite(const char *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Open a named file to write.
static bool fgXMLChBigEndian
Definition: PlatformUtils.hpp:134
static FileHandle openStdInHandle(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens the standard input as a file.
static XMLNetAccessor * fgNetAccessor
The network accessor.
Definition: PlatformUtils.hpp:87
static void writeBufferToFile(FileHandle const theFile, XMLSize_t toWrite, const XMLByte *const toFlush, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Writes the buffer to the file.
static FileHandle openFileToWrite(const XMLCh *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Open a named file to write.
static XMLFilePos fileSize(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Returns the file size.
static XMLCh * getCurrentDirectory(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Gets the current working directory.
static bool isRelative(const XMLCh *const toCheck, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Determines if a path is relative or absolute.
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...
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
static FileHandle openFile(const char *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens the file.
static bool isStrictIANAEncoding()
Returns whether a strict IANA encoding name check is enabled or disabled.
static void closeFile(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Closes the file handle.
static XMLMutex * fgAtomicMutex
Global mutex for fast or infrequent operations.
Definition: PlatformUtils.hpp:132
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.
static PanicHandler * fgUserPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:108
static void panic(const PanicHandler::PanicReasons reason)
The panic mechanism.
static XMLTransService * fgTransService
The transcoding service.
Definition: PlatformUtils.hpp:99
static XMLMutexMgr * makeMutexMgr(MemoryManager *const manager)
Factory method for creating MutexMgr object.
static PanicHandler * fgDefaultPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:114
static void Terminate()
Perform per-process parser termination.
static void * makeMutex(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Make a new mutex.
static void unlockMutex(void *const mtxHandle)
Unlocks a mutex.
static XMLCh * weavePaths(const XMLCh *const basePath, const XMLCh *const relativePath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Utility to join two paths.
static XMLMsgLoader * loadMsgSet(const XMLCh *const msgDomain)
Loads the message set from among the available domains.
static void removeDotSlash(XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Remove occurrences of the pair of dot slash.
Definition: TransService.hpp:53
static const char fgXercescDefaultLocale[]
Definition: XMLUni.hpp:304