- Main Page
- Related Pages
- Classes
- Files

# PlatformUtils.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Licensed to the Apache Software Foundation (ASF) under one or more
    00003  * contributor license agreements.  See the NOTICE file distributed with
    00004  * this work for additional information regarding copyright ownership.
    00005  * The ASF licenses this file to You under the Apache License, Version 2.0
    00006  * (the "License"); you may not use this file except in compliance with
    00007  * the License.  You may obtain a copy of the License at
    00008  *
    00009  *      http://www.apache.org/licenses/LICENSE-2.0
    00010  *
    00011  * Unless required by applicable law or agreed to in writing, software
    00012  * distributed under the License is distributed on an "AS IS" BASIS,
    00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00014  * See the License for the specific language governing permissions and
    00015  * limitations under the License.
    00016  */
    00017
    00018 /*
    00019  * $Id: PlatformUtils.hpp 932887 2010-04-11 13:04:59Z borisk $
    00020  */
    00021
    00022 #if !defined(XERCESC_INCLUDE_GUARD_PLATFORMUTILS_HPP)
    00023 #define XERCESC_INCLUDE_GUARD_PLATFORMUTILS_HPP
    00024
    00025 #include <xercesc/util/XercesDefs.hpp>
    00026 #include <xercesc/util/XMLException.hpp>
    00027 #include <xercesc/util/PanicHandler.hpp>
    00028
    00029 #include <xercesc/util/XMLFileMgr.hpp>
    00030 #include <xercesc/util/XMLMutexMgr.hpp>
    00031
    00032 XERCES_CPP_NAMESPACE_BEGIN
    00033
    00034 class XMLMsgLoader;
    00035 class XMLNetAccessor;
    00036 class XMLTransService;
    00037 class MemoryManager;
    00038 class XMLMutex;
    00039
    00040 //
    00041 //  For internal use only
    00042 //
    00043 //  This class provides a simple abstract API via which lazily evaluated
    00044 //  data can be cleaned up.
    00045 //
    00046 class XMLUTIL_EXPORT XMLDeleter
    00047 {
    00048 public :
    00049     virtual ~XMLDeleter();
    00050
    00051 protected :
    00052     XMLDeleter();
    00053
    00054 private :
    00055     XMLDeleter(const XMLDeleter&);
    00056     XMLDeleter& operator=(const XMLDeleter&);
    00057 };
    00058
    00059
    00068 class XMLUTIL_EXPORT XMLPlatformUtils
    00069 {
    00070 public :
    00071
    00074
    00087     static XMLNetAccessor*      fgNetAccessor;
    00088
    00099     static XMLTransService*     fgTransService;
    00100 #ifdef OS390
    00101     static XMLTransService*     fgTransService2;
    00102 #endif
    00103
    00108     static PanicHandler*        fgUserPanicHandler;
    00109
    00114     static PanicHandler*        fgDefaultPanicHandler;
    00115
    00121     static MemoryManager*       fgMemoryManager;
    00122
    00123     static XMLFileMgr*          fgFileMgr;
    00124     static XMLMutexMgr*         fgMutexMgr;
    00125
    00132     static XMLMutex*            fgAtomicMutex;
    00133
    00134     static bool                 fgXMLChBigEndian;
    00135     static bool                 fgSSE2ok;
    00137
    00138
    00141
    00173     static void Initialize(const char*          const locale = XMLUni::fgXercescDefaultLocale
    00174                          , const char*          const nlsHome = 0
    00175                          ,       PanicHandler*  const panicHandler = 0
    00176                          ,       MemoryManager* const memoryManager = 0);
    00177
    00227     static void Initialize(XMLSize_t initialDOMHeapAllocSize
    00228                          , XMLSize_t maxDOMHeapAllocSize
    00229                          , XMLSize_t maxDOMSubAllocationSize
    00230                          , const char*          const locale = XMLUni::fgXercescDefaultLocale
    00231                          , const char*          const nlsHome = 0
    00232                          ,       PanicHandler*  const panicHandler = 0
    00233                          ,       MemoryManager* const memoryManager = 0);
    00234
    00241     static void Terminate();
    00242
    00259     static void panic
    00260     (
    00261         const   PanicHandler::PanicReasons    reason
    00262     );
    00263
    00265
    00268
    00273     static XMLFileMgr* makeFileMgr(MemoryManager* const manager);
    00274
    00288     static XMLFilePos curFilePos(FileHandle theFile
    00289         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00290
    00301     static void closeFile(FileHandle theFile
    00302         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00303
    00314     static XMLFilePos fileSize(FileHandle theFile
    00315         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00316
    00327     static FileHandle openFile(const char* const fileName
    00328         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00329
    00340     static FileHandle openFile(const XMLCh* const fileName
    00341         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00342
    00353     static FileHandle openFileToWrite(const char* const fileName
    00354         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00355
    00366     static FileHandle openFileToWrite(const XMLCh* const fileName
    00367         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00368
    00379     static FileHandle openStdInHandle(MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00380
    00397     static XMLSize_t readFileBuffer
    00398     (
    00399                 FileHandle      theFile
    00400         , const XMLSize_t       toRead
    00401         ,       XMLByte* const  toFill
    00402         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
    00403     );
    00404
    00419     static void writeBufferToFile
    00420     (
    00421           FileHandle     const  theFile
    00422         , XMLSize_t             toWrite
    00423         , const XMLByte* const  toFlush
    00424         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
    00425     );
    00426
    00436     static void resetFile(FileHandle theFile
    00437         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
    00438
    00440
    00441
    00465     static XMLCh* getFullPath
    00466     (
    00467         const XMLCh* const srcPath
    00468         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00469     );
    00470
    00484     static XMLCh* getCurrentDirectory
    00485     (
    00486         MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00487     );
    00488
    00498     static inline bool isAnySlash(XMLCh c);
    00499
    00509     static void   removeDotSlash(XMLCh* const srcPath
    00510         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00511
    00522     static void   removeDotDotSlash(XMLCh* const srcPath
    00523         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00524
    00538     static bool isRelative(const XMLCh* const toCheck
    00539         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00540         );
    00541
    00561     static XMLCh* weavePaths
    00562     (
    00563         const   XMLCh* const    basePath
    00564         , const XMLCh* const    relativePath
    00565         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00566     );
    00568
    00571
    00581     static unsigned long getCurrentMillis();
    00583
    00586
    00594     static XMLMutexMgr* makeMutexMgr(MemoryManager* const manager);
    00595
    00604     static void closeMutex(void* const mtxHandle, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00605
    00613     static void lockMutex(void* const mtxHandle);
    00614
    00624     static void* makeMutex(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00625
    00638     static void unlockMutex(void* const mtxHandle);
    00639
    00641
    00642
    00645
    00653     static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
    00654
    00656
    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 XMLSize_t alignPointerForNewBlockAllocation(XMLSize_t ptrSize);
    00708
    00709 private :
    00710     // -----------------------------------------------------------------------
    00711     //  Unimplemented constructors and operators
    00712     // -----------------------------------------------------------------------
    00713     XMLPlatformUtils();
    00714
    00717
    00723     static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
    00724
    00734     static XMLNetAccessor* makeNetAccessor();
    00735
    00746     static XMLTransService* makeTransService();
    00747
    00755     static int  searchSlashDotDotSlash(XMLCh* const srcPath);
    00756
    00758
    00761
    00768     static bool fgMemMgrAdopted;
    00769
    00771 };
    00772
    00773
    00774 MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT)
    00775
    00776
    00777 // ---------------------------------------------------------------------------
    00778 //  XMLPlatformUtils: alignPointerForNewBlockAllocation
    00779 // ---------------------------------------------------------------------------
    00780 //  Calculate alignment required by platform for a new
    00781 //  block allocation. We use this in our custom allocators
    00782 //  to ensure that returned blocks are properly aligned.
    00783 //  Note that, although this will take a pointer and return the position
    00784 //  at which it should be placed for correct alignment, in our code
    00785 //  we normally use XMLSize_t parameters to discover what the alignment
    00786 //  of header blocks should be.  Thus, if this is to be
    00787 //  used for the former purpose, to make compilers happy
    00788 //  some casting will be necessary - neilg.
    00789 //
    00790 //  Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
    00791 //        per-architecture basis to dictate the alignment requirements
    00792 //        of the architecture. In the absense of this specification,
    00793 //        this routine guesses at the correct alignment value.
    00794 //
    00795 //        A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
    00796 //        If a platform requires absolutely no alignment, a value
    00797 //        of 1 should be specified ("align pointers on 1 byte boundaries").
    00798 //
    00799 inline XMLSize_t
    00800 XMLPlatformUtils::alignPointerForNewBlockAllocation(XMLSize_t ptrSize)
    00801 {
    00802     //    Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
    00803     //    as needed to dictate alignment requirements on a
    00804     //    per-architecture basis. In the absense of that we
    00805     //    take an educated guess.
    00806 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
    00807     static const XMLSize_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
    00808 #else
    00809     static const XMLSize_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
    00810 #endif
    00811
    00812     //    Calculate current alignment of pointer
    00813     XMLSize_t current = ptrSize % alignment;
    00814
    00815     //    Adjust pointer alignment as needed
    00816     return (current == 0)
    00817          ? ptrSize
    00818          : (ptrSize + alignment - current);
    00819 }
    00820
    00821
    00822
    00823 // ---------------------------------------------------------------------------
    00824 //  XMLDeleter: Public Destructor
    00825 // ---------------------------------------------------------------------------
    00826 inline XMLDeleter::~XMLDeleter()
    00827 {
    00828 }
    00829
    00830 // ---------------------------------------------------------------------------
    00831 //  XMLDeleter: Hidden constructors and operators
    00832 // ---------------------------------------------------------------------------
    00833 inline XMLDeleter::XMLDeleter()
    00834 {
    00835 }
    00836
    00837 XERCES_CPP_NAMESPACE_END
    00838
    00839 #endif