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 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 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
00175 static void Terminate();
00176
00193 static void panic
00194 (
00195 const PanicHandler::PanicReasons reason
00196 );
00197
00199
00202
00216 static unsigned int curFilePos(FileHandle theFile
00217 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00218
00229 static void closeFile(FileHandle theFile
00230 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00231
00242 static unsigned int fileSize(FileHandle theFile
00243 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00244
00255 static FileHandle openFile(const char* const fileName
00256 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00257
00268 static FileHandle openFile(const XMLCh* const fileName
00269 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00270
00281 static FileHandle openFileToWrite(const char* const fileName
00282 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00283
00294 static FileHandle openFileToWrite(const XMLCh* const fileName
00295 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00296
00307 static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00308
00325 static unsigned int readFileBuffer
00326 (
00327 FileHandle theFile
00328 , const unsigned int toRead
00329 , XMLByte* const toFill
00330 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00331 );
00332
00347 static void writeBufferToFile
00348 (
00349 FileHandle const theFile
00350 , long toWrite
00351 , const XMLByte* const toFlush
00352 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00353 );
00354
00364 static void resetFile(FileHandle theFile
00365 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00366
00368
00369
00393 static XMLCh* getFullPath
00394 (
00395 const XMLCh* const srcPath
00396 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00397 );
00398
00412 static XMLCh* getCurrentDirectory
00413 (
00414 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00415 );
00416
00426 static inline bool isAnySlash(XMLCh c);
00427
00437 static void removeDotSlash(XMLCh* const srcPath
00438 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00439
00450 static void removeDotDotSlash(XMLCh* const srcPath
00451 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00452
00466 static bool isRelative(const XMLCh* const toCheck
00467 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00468 );
00469
00489 static XMLCh* weavePaths
00490 (
00491 const XMLCh* const basePath
00492 , const XMLCh* const relativePath
00493 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00494 );
00496
00499
00509 static unsigned long getCurrentMillis();
00511
00514
00522 static void closeMutex(void* const mtxHandle);
00523
00531 static void lockMutex(void* const mtxHandle);
00532
00540 static void* makeMutex();
00541
00554 static void unlockMutex(void* const mtxHandle);
00555
00557
00558
00561
00569 static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
00570
00572
00575
00601 static void* compareAndSwap
00602 (
00603 void** toFill
00604 , const void* const newValue
00605 , const void* const toCompare
00606 );
00607
00609
00610
00613
00633 static int atomicIncrement(int& location);
00634
00654 static int atomicDecrement(int& location);
00655
00657
00671 static void recognizeNEL(bool state
00672 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00673
00677 static bool isNELRecognized();
00679
00691 static void strictIANAEncoding(const bool state);
00692
00697 static bool isStrictIANAEncoding();
00699
00707 static inline size_t alignPointerForNewBlockAllocation(size_t ptrSize);
00708
00709 private :
00710
00711
00712
00713 XMLPlatformUtils();
00714
00717
00723 static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
00724
00734 static XMLNetAccessor* makeNetAccessor();
00735
00746 static XMLTransService* makeTransService();
00747
00754 static void platformInit();
00755
00762 static void platformTerm();
00763
00771 static int searchSlashDotDotSlash(XMLCh* const srcPath);
00772
00774
00777
00784 static bool fgMemMgrAdopted;
00785
00787 };
00788
00789
00790 MakeXMLException(XMLPlatformUtilsException, )
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 inline size_t
00816 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
00817 {
00818
00819
00820
00821
00822 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
00823 size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
00824 #else
00825 size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
00826 #endif
00827
00828
00829 size_t current = ptrSize % alignment;
00830
00831
00832 return (current == 0)
00833 ? ptrSize
00834 : (ptrSize + alignment - current);
00835 }
00836
00837
00838
00839
00840
00841
00842 inline XMLDeleter::~XMLDeleter()
00843 {
00844 }
00845
00846
00847
00848
00849 inline XMLDeleter::XMLDeleter()
00850 {
00851 }
00852
00853 XERCES_CPP_NAMESPACE_END
00854
00855 #endif