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
25 #include <xercesc/util/XercesDefs.hpp>
26 #include <xercesc/util/XMLException.hpp>
27 #include <xercesc/util/PanicHandler.hpp>
28
29 #include <xercesc/util/XMLFileMgr.hpp>
30 #include <xercesc/util/XMLMutexMgr.hpp>
31
32 XERCES_CPP_NAMESPACE_BEGIN
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 //
46 class XMLUTIL_EXPORT XMLDeleter
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
68 class XMLUTIL_EXPORT XMLPlatformUtils
69 {
70 public :
71
74
87 static XMLNetAccessor* fgNetAccessor;
88
99 static XMLTransService* fgTransService;
100 #ifdef OS390
101 static XMLTransService* fgTransService2;
102 #endif
103
108 static PanicHandler* fgUserPanicHandler;
109
114 static PanicHandler* fgDefaultPanicHandler;
115
121 static MemoryManager* fgMemoryManager;
122
123 static XMLFileMgr* fgFileMgr;
124 static XMLMutexMgr* fgMutexMgr;
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
288 static XMLFilePos curFilePos(FileHandle theFile
289 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
290
301 static void closeFile(FileHandle theFile
302 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
303
314 static XMLFilePos fileSize(FileHandle theFile
315 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
316
327 static FileHandle openFile(const char* const fileName
328 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
329
340 static FileHandle openFile(const XMLCh* const fileName
341 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
342
353 static FileHandle openFileToWrite(const char* const fileName
354 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
355
366 static FileHandle openFileToWrite(const XMLCh* const fileName
367 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
368
379 static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
380
397 static XMLSize_t readFileBuffer
398 (
399 FileHandle theFile
400 , const XMLSize_t toRead
401 , XMLByte* const toFill
402 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
403 );
404
419 static void writeBufferToFile
420 (
421 FileHandle const theFile
422 , XMLSize_t toWrite
423 , const XMLByte* const toFlush
424 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
425 );
426
436 static void resetFile(FileHandle theFile
437 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
438
440
441
465 static XMLCh* getFullPath
466 (
467 const XMLCh* const srcPath
468 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
469 );
470
484 static XMLCh* getCurrentDirectory
485 (
486 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
487 );
488
498 static inline bool isAnySlash(XMLCh c);
499
509 static void removeDotSlash(XMLCh* const srcPath
510 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
511
522 static void removeDotDotSlash(XMLCh* const srcPath
523 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
524
538 static bool isRelative(const XMLCh* const toCheck
539 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
540 );
541
561 static XMLCh* weavePaths
562 (
563 const XMLCh* const basePath
564 , const XMLCh* const relativePath
565 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
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
624 static void* makeMutex(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
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
672 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
673
677 static bool isNELRecognized();
679
691 static void strictIANAEncoding(const bool state);
692
697 static bool isStrictIANAEncoding();
699
707 static inline XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize);
708
709 private :
710 // -----------------------------------------------------------------------
711 // Unimplemented constructors and operators
712 // -----------------------------------------------------------------------
713 XMLPlatformUtils();
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
800 XMLPlatformUtils::alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
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 // ---------------------------------------------------------------------------
826 inline XMLDeleter::~XMLDeleter()
827 {
828 }
829
830 // ---------------------------------------------------------------------------
831 // XMLDeleter: Hidden constructors and operators
832 // ---------------------------------------------------------------------------
833 inline XMLDeleter::XMLDeleter()
834 {
835 }
836
837 XERCES_CPP_NAMESPACE_END
838
839 #endif
PanicHandler.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLNetAccessor
Definition: XMLNetAccessor.hpp:95
XMLPlatformUtils::fgMutexMgr
static XMLMutexMgr * fgMutexMgr
Definition: PlatformUtils.hpp:124
XMLPlatformUtils::fgDefaultPanicHandler
static PanicHandler * fgDefaultPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:114
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
PanicHandler
Receive notification of panic.
Definition: PanicHandler.hpp:44
XMLPlatformUtils::fgFileMgr
static XMLFileMgr * fgFileMgr
Definition: PlatformUtils.hpp:123
XMLDeleter::XMLDeleter
XMLDeleter()
Definition: PlatformUtils.hpp:833
XMLByte
unsigned char XMLByte
Definition: XercesDefs.hpp:65
XMLPlatformUtils::fgNetAccessor
static XMLNetAccessor * fgNetAccessor
The network accessor.
Definition: PlatformUtils.hpp:87
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
XMLPlatformUtils::fgSSE2ok
static bool fgSSE2ok
Definition: PlatformUtils.hpp:135
XMLTransService
Definition: TransService.hpp:52
XMLUni::fgXercescDefaultLocale
static const char fgXercescDefaultLocale[]
Definition: XMLUni.hpp:304
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
XMLException.hpp
XMLDeleter::~XMLDeleter
virtual ~XMLDeleter()
Definition: PlatformUtils.hpp:826
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
XMLFilePos
XMLUInt64 XMLFilePos
Definition: Xerces_autoconf_config.hpp:139
XMLFileMgr.hpp
XMLPlatformUtils
Utilities that must be implemented in a platform-specific way.
Definition: PlatformUtils.hpp:68
PanicHandler::PanicReasons
PanicReasons
Definition: PanicHandler.hpp:50
XercesDefs.hpp
XMLMutexMgr
Definition: XMLMutexMgr.hpp:33
XMLPlatformUtils::fgUserPanicHandler
static PanicHandler * fgUserPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:108
XMLDeleter
Definition: PlatformUtils.hpp:46
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:39
MakeXMLException
MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT) inline XMLSize_t XMLPlatformUtils
Definition: PlatformUtils.hpp:774
XMLMutexMgr.hpp
XMLPlatformUtils::alignPointerForNewBlockAllocation
static XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
Aligns the specified pointer per platform block allocation requirements.
XMLFileMgr
Definition: XMLFileMgr.hpp:34
XMLPlatformUtils::fgXMLChBigEndian
static bool fgXMLChBigEndian
Definition: PlatformUtils.hpp:134
FileHandle
XERCES_CPP_NAMESPACE_BEGIN typedef void * FileHandle
Definition: XMLFileMgr.hpp:30
XMLPlatformUtils::fgAtomicMutex
static XMLMutex * fgAtomicMutex
Global mutex for fast or infrequent operations.
Definition: PlatformUtils.hpp:132
XMLPlatformUtils::fgTransService
static XMLTransService * fgTransService
The transcoding service.
Definition: PlatformUtils.hpp:99