SourceForge.net Logo
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 
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  // -----------------------------------------------------------------------
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
Configurable memory manager.
Definition: MemoryManager.hpp:40
Definition: PlatformUtils.hpp:47
Utilities that must be implemented in a platform-specific way.
Definition: PlatformUtils.hpp:69
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 XMLCh * getCurrentDirectory(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Gets the current working directory.
static XMLMutexMgr * fgMutexMgr
Definition: PlatformUtils.hpp:124
static XMLTransService * fgTransService
The transcoding service.
Definition: PlatformUtils.hpp:99
static XMLFilePos curFilePos(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get the current file position.
static void unlockMutex(void *const mtxHandle)
Unlocks a mutex.
static FileHandle openFileToWrite(const char *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Open a named file to write.
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
static bool isNELRecognized()
Return the value of fgNEL flag.
static PanicHandler * fgUserPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:108
static void closeMutex(void *const mtxHandle, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Closes a mutex handle.
static XMLMutex * fgAtomicMutex
Global mutex for fast or infrequent operations.
Definition: PlatformUtils.hpp:132
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 FileHandle openFileToWrite(const XMLCh *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Open a named file to write.
static bool isStrictIANAEncoding()
Returns whether a strict IANA encoding name check is enabled or disabled.
static FileHandle openFile(const char *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens the file.
static XMLFileMgr * fgFileMgr
Definition: PlatformUtils.hpp:123
static bool isAnySlash(XMLCh c)
Check if a character is a slash.
static bool fgXMLChBigEndian
Definition: PlatformUtils.hpp:134
static XMLNetAccessor * fgNetAccessor
The network accessor.
Definition: PlatformUtils.hpp:87
static XMLCh * weavePaths(const XMLCh *const basePath, const XMLCh *const relativePath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Utility to join two paths.
static unsigned long getCurrentMillis()
Gets the system time in milliseconds.
static void strictIANAEncoding(const bool state)
This function enables/disables strict IANA encoding names checking.
static void panic(const PanicHandler::PanicReasons reason)
The panic mechanism.
static void removeDotDotSlash(XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Remove occurrences of the dot dot slash.
static void Terminate()
Perform per-process parser termination.
static FileHandle openFile(const XMLCh *const fileName, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens a named file.
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 openStdInHandle(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Opens the standard input as a file.
static XMLFileMgr * makeFileMgr(MemoryManager *const manager)
Make a new file object appropriate for the platform.
static XMLFilePos fileSize(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Returns the file size.
static void lockMutex(void *const mtxHandle)
Locks a mutex handle.
static XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
Aligns the specified pointer per platform block allocation requirements.
static XMLSize_t readFileBuffer(FileHandle theFile, const XMLSize_t toRead, XMLByte *const toFill, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Reads the file buffer.
static void * makeMutex(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Make a new mutex.
static void closeFile(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Closes the file handle.
static void removeDotSlash(XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Remove occurrences of the pair of dot slash.
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 * fgDefaultPanicHandler
The Panic Handler.
Definition: PlatformUtils.hpp:114
static XMLCh * getFullPath(const XMLCh *const srcPath, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Gets the full path from a relative path.
static XMLMutexMgr * makeMutexMgr(MemoryManager *const manager)
Factory method for creating MutexMgr object.
static XMLMsgLoader * loadMsgSet(const XMLCh *const msgDomain)
Loads the message set from among the available domains.
static bool fgSSE2ok
Definition: PlatformUtils.hpp:135
static void resetFile(FileHandle theFile, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Resets the file handle.
static bool isRelative(const XMLCh *const toCheck, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Determines if a path is relative or absolute.
MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT) inline XMLSize_t XMLPlatformUtils
Definition: PlatformUtils.hpp:774