00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #if !defined(PLATFORMUTILS_HPP)
00063 #define PLATFORMUTILS_HPP
00064
00065 #include <xercesc/util/XMLException.hpp>
00066 #include <xercesc/util/PanicHandler.hpp>
00067
00068 XERCES_CPP_NAMESPACE_BEGIN
00069
00070 class XMLMsgLoader;
00071 class XMLNetAccessor;
00072 class XMLTransService;
00073 class MemoryManager;
00074 class XMLMutex;
00075
00076
00077
00078
00079
00080
00081
00082 class XMLDeleter
00083 {
00084 public :
00085 virtual ~XMLDeleter();
00086
00087 protected :
00088 XMLDeleter();
00089
00090 private :
00091 XMLDeleter(const XMLDeleter&);
00092 XMLDeleter& operator=(const XMLDeleter&);
00093 };
00094
00095
00104 class XMLPlatformUtils
00105 {
00106 public :
00107
00110
00123 static XMLNetAccessor* fgNetAccessor;
00124
00135 static XMLTransService* fgTransService;
00136
00141 static PanicHandler* fgUserPanicHandler;
00142
00147 static PanicHandler* fgDefaultPanicHandler;
00148
00154 static MemoryManager* fgMemoryManager;
00155
00164 static MemoryManager* fgArrayMemoryManager;
00165
00166 static XMLMutex* fgAtomicMutex;
00167
00169
00170
00173
00204 static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
00205 , const char* const nlsHome = 0
00206 , PanicHandler* const panicHandler = 0
00207 , MemoryManager* const memoryManager = 0);
00208
00215 static void Terminate();
00216
00233 static void panic
00234 (
00235 const PanicHandler::PanicReasons reason
00236 );
00237
00239
00242
00255 static unsigned int curFilePos(FileHandle theFile
00256 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00257
00267 static void closeFile(FileHandle theFile
00268 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00269
00280 static unsigned int fileSize(FileHandle theFile
00281 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00282
00293 static FileHandle openFile(const char* const fileName
00294 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00295
00306 static FileHandle openFile(const XMLCh* const fileName
00307 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00308
00319 static FileHandle openFileToWrite(const char* const fileName
00320 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00321
00332 static FileHandle openFileToWrite(const XMLCh* const fileName
00333 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00334
00344 static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00345
00361 static unsigned int readFileBuffer
00362 (
00363 FileHandle theFile
00364 , const unsigned int toRead
00365 , XMLByte* const toFill
00366 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00367 );
00368
00383 static void writeBufferToFile
00384 (
00385 FileHandle const theFile
00386 , long toWrite
00387 , const XMLByte* const toFlush
00388 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00389 );
00390
00399 static void resetFile(FileHandle theFile
00400 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00401
00403
00404
00428 static XMLCh* getFullPath
00429 (
00430 const XMLCh* const srcPath
00431 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00432 );
00433
00447 static XMLCh* getCurrentDirectory
00448 (
00449 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00450 );
00451
00461 static inline bool isAnySlash(XMLCh c);
00462
00472 static void removeDotSlash(XMLCh* const srcPath
00473 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00474
00485 static void removeDotDotSlash(XMLCh* const srcPath
00486 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00487
00501 static bool isRelative(const XMLCh* const toCheck
00502 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00503 );
00504
00524 static XMLCh* weavePaths
00525 (
00526 const XMLCh* const basePath
00527 , const XMLCh* const relativePath
00528 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00529 );
00531
00534
00544 static unsigned long getCurrentMillis();
00546
00549
00557 static void closeMutex(void* const mtxHandle);
00558
00566 static void lockMutex(void* const mtxHandle);
00567
00575 static void* makeMutex();
00576
00589 static void unlockMutex(void* const mtxHandle);
00590
00592
00593
00596
00604 static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
00605
00607
00610
00636 static void* compareAndSwap
00637 (
00638 void** toFill
00639 , const void* const newValue
00640 , const void* const toCompare
00641 );
00642
00644
00645
00648
00668 static int atomicIncrement(int& location);
00669
00689 static int atomicDecrement(int& location);
00690
00692
00706 static void recognizeNEL(bool state
00707 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00708
00712 static bool isNELRecognized();
00714
00726 static void strictIANAEncoding(const bool state);
00727
00732 static bool isStrictIANAEncoding();
00734
00742 static inline size_t alignPointerForNewBlockAllocation(size_t ptrSize);
00743
00744 private :
00745
00746
00747
00748 XMLPlatformUtils();
00749
00752
00758 static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
00759
00769 static XMLNetAccessor* makeNetAccessor();
00770
00781 static XMLTransService* makeTransService();
00782
00789 static void platformInit();
00790
00797 static void platformTerm();
00798
00806 static int searchSlashDotDotSlash(XMLCh* const srcPath);
00807
00809
00812
00819 static bool fgMemMgrAdopted;
00820
00822 };
00823
00824
00825 MakeXMLException(XMLPlatformUtilsException, )
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850 inline size_t
00851 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
00852 {
00853
00854
00855
00856
00857 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
00858 size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
00859 #else
00860 size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
00861 #endif
00862
00863
00864 size_t current = ptrSize % alignment;
00865
00866
00867 return (current == 0)
00868 ? ptrSize
00869 : (ptrSize + alignment - current);
00870 }
00871
00872
00873
00874
00875
00876
00877 inline XMLDeleter::~XMLDeleter()
00878 {
00879 }
00880
00881
00882
00883
00884 inline XMLDeleter::XMLDeleter()
00885 {
00886 }
00887
00888 XERCES_CPP_NAMESPACE_END
00889
00890 #endif