| API Docs for SAX and DOM |

- Main Page
- Classes
- Files
- Related Pages

# 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 568078 2007-08-21 11:43:25Z amassari $
    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 //  For internal use only
    00039 //
    00040 //  This class provides a simple abstract API via which lazily evaluated
    00041 //  data can be cleaned up.
    00042 //
    00043 class  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  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     //  Unimplemented constructors and operators
    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, )
    00798
    00799
    00800 // ---------------------------------------------------------------------------
    00801 //  XMLPlatformUtils: alignPointerForNewBlockAllocation
    00802 // ---------------------------------------------------------------------------
    00803 //  Calculate alignment required by platform for a new
    00804 //  block allocation. We use this in our custom allocators
    00805 //  to ensure that returned blocks are properly aligned.
    00806 //  Note that, although this will take a pointer and return the position
    00807 //  at which it should be placed for correct alignment, in our code
    00808 //  we normally use size_t parameters to discover what the alignment
    00809 //  of header blocks should be.  Thus, if this is to be
    00810 //  used for the former purpose, to make compilers happy
    00811 //  some casting will be necessary - neilg.
    00812 //
    00813 //  Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
    00814 //        per-architecture basis to dictate the alignment requirements
    00815 //        of the architecture. In the absense of this specification,
    00816 //        this routine guesses at the correct alignment value.
    00817 //
    00818 //        A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
    00819 //        If a platform requires absolutely no alignment, a value
    00820 //        of 1 should be specified ("align pointers on 1 byte boundaries").
    00821 //
    00822 inline size_t
    00823 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
    00824 {
    00825     //  Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
    00826     //  as needed to dictate alignment requirements on a
    00827     //  per-architecture basis. In the absense of that we
    00828     //  take an educated guess.
    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     //  Calculate current alignment of pointer
    00836     size_t current = ptrSize % alignment;
    00837
    00838     //  Adjust pointer alignment as needed
    00839     return (current == 0)
    00840          ? ptrSize
    00841          : (ptrSize + alignment - current);
    00842 }
    00843
    00844
    00845
    00846 // ---------------------------------------------------------------------------
    00847 //  XMLDeleter: Public Destructor
    00848 // ---------------------------------------------------------------------------
    00849 inline XMLDeleter::~XMLDeleter()
    00850 {
    00851 }
    00852
    00853 // ---------------------------------------------------------------------------
    00854 //  XMLDeleter: Hidden constructors and operators
    00855 // ---------------------------------------------------------------------------
    00856 inline XMLDeleter::XMLDeleter()
    00857 {
    00858 }
    00859
    00860 XERCES_CPP_NAMESPACE_END
    00861
    00862 #endif

Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.