00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined(PLATFORMUTILS_HPP)
00024 #define PLATFORMUTILS_HPP
00025
00026 #include <xercesc/util/XMLException.hpp>
00027 #include <xercesc/util/PanicHandler.hpp>
00028
00029 XERCES_CPP_NAMESPACE_BEGIN
00030
00031 class XMLMsgLoader;
00032 class XMLNetAccessor;
00033 class XMLTransService;
00034 class MemoryManager;
00035 class XMLMutex;
00036
00037
00038
00039
00040
00041
00042
00043 class XMLUTIL_EXPORT XMLDeleter
00044 {
00045 public :
00046 virtual ~XMLDeleter();
00047
00048 protected :
00049 XMLDeleter();
00050
00051 private :
00052 XMLDeleter(const XMLDeleter&);
00053 XMLDeleter& operator=(const XMLDeleter&);
00054 };
00055
00056
00065 class XMLUTIL_EXPORT XMLPlatformUtils
00066 {
00067 public :
00068
00071
00084 static XMLNetAccessor* fgNetAccessor;
00085
00096 static XMLTransService* fgTransService;
00097 #ifdef OS390
00098 static XMLTransService* fgTransService2;
00099 #endif
00100
00105 static PanicHandler* fgUserPanicHandler;
00106
00111 static PanicHandler* fgDefaultPanicHandler;
00112
00118 static MemoryManager* fgMemoryManager;
00119
00128 static MemoryManager* fgArrayMemoryManager;
00129
00130 static XMLMutex* fgAtomicMutex;
00131
00133
00134
00137
00168 static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
00169 , const char* const nlsHome = 0
00170 , PanicHandler* const panicHandler = 0
00171 , MemoryManager* const memoryManager = 0
00172 , bool toInitStatics = false);
00173
00180 static void Terminate();
00181
00198 static void panic
00199 (
00200 const PanicHandler::PanicReasons reason
00201 );
00202
00204
00207
00221 static unsigned int curFilePos(FileHandle theFile
00222 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00223
00234 static void closeFile(FileHandle theFile
00235 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00236
00247 static unsigned int fileSize(FileHandle theFile
00248 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00249
00260 static FileHandle openFile(const char* const fileName
00261 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00262
00273 static FileHandle openFile(const XMLCh* const fileName
00274 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00275
00286 static FileHandle openFileToWrite(const char* const fileName
00287 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00288
00299 static FileHandle openFileToWrite(const XMLCh* const fileName
00300 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00301
00312 static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00313
00330 static unsigned int readFileBuffer
00331 (
00332 FileHandle theFile
00333 , const unsigned int toRead
00334 , XMLByte* const toFill
00335 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00336 );
00337
00352 static void writeBufferToFile
00353 (
00354 FileHandle const theFile
00355 , long toWrite
00356 , const XMLByte* const toFlush
00357 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00358 );
00359
00369 static void resetFile(FileHandle theFile
00370 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00371
00373
00374
00398 static XMLCh* getFullPath
00399 (
00400 const XMLCh* const srcPath
00401 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00402 );
00403
00417 static XMLCh* getCurrentDirectory
00418 (
00419 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00420 );
00421
00431 static inline bool isAnySlash(XMLCh c);
00432
00442 static void removeDotSlash(XMLCh* const srcPath
00443 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00444
00455 static void removeDotDotSlash(XMLCh* const srcPath
00456 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00457
00471 static bool isRelative(const XMLCh* const toCheck
00472 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00473 );
00474
00494 static XMLCh* weavePaths
00495 (
00496 const XMLCh* const basePath
00497 , const XMLCh* const relativePath
00498 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00499 );
00501
00504
00514 static unsigned long getCurrentMillis();
00516
00519
00527 static void closeMutex(void* const mtxHandle);
00528
00536 static void lockMutex(void* const mtxHandle);
00537
00547 static void* makeMutex(MemoryManager* manager = XMLPlatformUtils::fgMemoryManager);
00548
00561 static void unlockMutex(void* const mtxHandle);
00562
00564
00565
00568
00576 static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
00577
00579
00582
00608 static void* compareAndSwap
00609 (
00610 void** toFill
00611 , const void* const newValue
00612 , const void* const toCompare
00613 );
00614
00616
00617
00620
00640 static int atomicIncrement(int& location);
00641
00661 static int atomicDecrement(int& location);
00662
00664
00678 static void recognizeNEL(bool state
00679 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00680
00684 static bool isNELRecognized();
00686
00698 static void strictIANAEncoding(const bool state);
00699
00704 static bool isStrictIANAEncoding();
00706
00714 static inline size_t alignPointerForNewBlockAllocation(size_t ptrSize);
00715
00716 private :
00717
00718
00719
00720 XMLPlatformUtils();
00721
00724
00730 static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
00731
00741 static XMLNetAccessor* makeNetAccessor();
00742
00753 static XMLTransService* makeTransService();
00754
00761 static void platformInit();
00762
00769 static void platformTerm();
00770
00778 static int searchSlashDotDotSlash(XMLCh* const srcPath);
00779
00781
00784
00791 static bool fgMemMgrAdopted;
00792
00794 };
00795
00796
00797 MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT)
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822 inline size_t
00823 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
00824 {
00825
00826
00827
00828
00829 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
00830 size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
00831 #else
00832 size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
00833 #endif
00834
00835
00836 size_t current = ptrSize % alignment;
00837
00838
00839 return (current == 0)
00840 ? ptrSize
00841 : (ptrSize + alignment - current);
00842 }
00843
00844
00845
00846
00847
00848
00849 inline XMLDeleter::~XMLDeleter()
00850 {
00851 }
00852
00853
00854
00855
00856 inline XMLDeleter::XMLDeleter()
00857 {
00858 }
00859
00860 XERCES_CPP_NAMESPACE_END
00861
00862 #endif