00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(PLATFORMUTILS_HPP)
00023 #define PLATFORMUTILS_HPP
00024
00025 #include <xercesc/util/XMLException.hpp>
00026 #include <xercesc/util/PanicHandler.hpp>
00027
00028 XERCES_CPP_NAMESPACE_BEGIN
00029
00030 class XMLMsgLoader;
00031 class XMLNetAccessor;
00032 class XMLTransService;
00033 class MemoryManager;
00034 class XMLMutex;
00035
00036
00037
00038
00039
00040
00041
00042 class XMLUTIL_EXPORT XMLDeleter
00043 {
00044 public :
00045 virtual ~XMLDeleter();
00046
00047 protected :
00048 XMLDeleter();
00049
00050 private :
00051 XMLDeleter(const XMLDeleter&);
00052 XMLDeleter& operator=(const XMLDeleter&);
00053 };
00054
00055
00064 class XMLUTIL_EXPORT XMLPlatformUtils
00065 {
00066 public :
00067
00070
00083 static XMLNetAccessor* fgNetAccessor;
00084
00095 static XMLTransService* fgTransService;
00096
00101 static PanicHandler* fgUserPanicHandler;
00102
00107 static PanicHandler* fgDefaultPanicHandler;
00108
00114 static MemoryManager* fgMemoryManager;
00115
00124 static MemoryManager* fgArrayMemoryManager;
00125
00126 static XMLMutex* fgAtomicMutex;
00127
00129
00130
00133
00164 static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
00165 , const char* const nlsHome = 0
00166 , PanicHandler* const panicHandler = 0
00167 , MemoryManager* const memoryManager = 0
00168 , bool toInitStatics = false);
00169
00176 static void Terminate();
00177
00194 static void panic
00195 (
00196 const PanicHandler::PanicReasons reason
00197 );
00198
00200
00203
00217 static unsigned int curFilePos(FileHandle theFile
00218 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00219
00230 static void closeFile(FileHandle theFile
00231 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00232
00243 static unsigned int fileSize(FileHandle theFile
00244 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00245
00256 static FileHandle openFile(const char* const fileName
00257 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00258
00269 static FileHandle openFile(const XMLCh* const fileName
00270 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00271
00282 static FileHandle openFileToWrite(const char* const fileName
00283 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00284
00295 static FileHandle openFileToWrite(const XMLCh* const fileName
00296 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00297
00308 static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00309
00326 static unsigned int readFileBuffer
00327 (
00328 FileHandle theFile
00329 , const unsigned int toRead
00330 , XMLByte* const toFill
00331 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00332 );
00333
00348 static void writeBufferToFile
00349 (
00350 FileHandle const theFile
00351 , long toWrite
00352 , const XMLByte* const toFlush
00353 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00354 );
00355
00365 static void resetFile(FileHandle theFile
00366 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00367
00369
00370
00394 static XMLCh* getFullPath
00395 (
00396 const XMLCh* const srcPath
00397 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00398 );
00399
00413 static XMLCh* getCurrentDirectory
00414 (
00415 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00416 );
00417
00427 static inline bool isAnySlash(XMLCh c);
00428
00438 static void removeDotSlash(XMLCh* const srcPath
00439 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00440
00451 static void removeDotDotSlash(XMLCh* const srcPath
00452 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00453
00467 static bool isRelative(const XMLCh* const toCheck
00468 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00469 );
00470
00490 static XMLCh* weavePaths
00491 (
00492 const XMLCh* const basePath
00493 , const XMLCh* const relativePath
00494 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00495 );
00497
00500
00510 static unsigned long getCurrentMillis();
00512
00515
00523 static void closeMutex(void* const mtxHandle);
00524
00532 static void lockMutex(void* const mtxHandle);
00533
00543 static void* makeMutex(MemoryManager* manager = XMLPlatformUtils::fgMemoryManager);
00544
00557 static void unlockMutex(void* const mtxHandle);
00558
00560
00561
00564
00572 static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
00573
00575
00578
00604 static void* compareAndSwap
00605 (
00606 void** toFill
00607 , const void* const newValue
00608 , const void* const toCompare
00609 );
00610
00612
00613
00616
00636 static int atomicIncrement(int& location);
00637
00657 static int atomicDecrement(int& location);
00658
00660
00674 static void recognizeNEL(bool state
00675 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00676
00680 static bool isNELRecognized();
00682
00694 static void strictIANAEncoding(const bool state);
00695
00700 static bool isStrictIANAEncoding();
00702
00710 static inline size_t alignPointerForNewBlockAllocation(size_t ptrSize);
00711
00712 private :
00713
00714
00715
00716 XMLPlatformUtils();
00717
00720
00726 static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
00727
00737 static XMLNetAccessor* makeNetAccessor();
00738
00749 static XMLTransService* makeTransService();
00750
00757 static void platformInit();
00758
00765 static void platformTerm();
00766
00774 static int searchSlashDotDotSlash(XMLCh* const srcPath);
00775
00777
00780
00787 static bool fgMemMgrAdopted;
00788
00790 };
00791
00792
00793 MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT)
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818 inline size_t
00819 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
00820 {
00821
00822
00823
00824
00825 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
00826 size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
00827 #else
00828 size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
00829 #endif
00830
00831
00832 size_t current = ptrSize % alignment;
00833
00834
00835 return (current == 0)
00836 ? ptrSize
00837 : (ptrSize + alignment - current);
00838 }
00839
00840
00841
00842
00843
00844
00845 inline XMLDeleter::~XMLDeleter()
00846 {
00847 }
00848
00849
00850
00851
00852 inline XMLDeleter::XMLDeleter()
00853 {
00854 }
00855
00856 XERCES_CPP_NAMESPACE_END
00857
00858 #endif