Xerces-C++: PlatformUtils.hpp Source File

| API Docs for SAX and DOM |
| Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages # PlatformUtils.hpp Go to the documentation of this file.
    00001 /*
    00002  * Copyright 1999-2004 The Apache Software Foundation.
    00003  *
    00004  * Licensed under the Apache License, Version 2.0 (the "License");
    00005  * you may not use this file except in compliance with the License.
    00006  * You may obtain a copy of the License at
    00007  *
    00008  *      http://www.apache.org/licenses/LICENSE-2.0
    00009  *
    00010  * Unless required by applicable law or agreed to in writing, software
    00011  * distributed under the License is distributed on an "AS IS" BASIS,
    00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013  * See the License for the specific language governing permissions and
    00014  * limitations under the License.
    00015  */
    00016
    00017 /*
    00018  * $Id: PlatformUtils.hpp 180016 2005-06-04 19:49:30Z jberry $
    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 //  For internal use only
    00038 //
    00039 //  This class provides a simple abstract API via which lazily evaluated
    00040 //  data can be cleaned up.
    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                          ,       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     //  Unimplemented constructors and operators
    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, )
    00794
    00795
    00796 // ---------------------------------------------------------------------------
    00797 //  XMLPlatformUtils: alignPointerForNewBlockAllocation
    00798 // ---------------------------------------------------------------------------
    00799 //  Calculate alignment required by platform for a new
    00800 //  block allocation. We use this in our custom allocators
    00801 //  to ensure that returned blocks are properly aligned.
    00802 //  Note that, although this will take a pointer and return the position
    00803 //  at which it should be placed for correct alignment, in our code
    00804 //  we normally use size_t parameters to discover what the alignment
    00805 //  of header blocks should be.  Thus, if this is to be
    00806 //  used for the former purpose, to make compilers happy
    00807 //  some casting will be necessary - neilg.
    00808 //
    00809 //  Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
    00810 //        per-architecture basis to dictate the alignment requirements
    00811 //        of the architecture. In the absense of this specification,
    00812 //        this routine guesses at the correct alignment value.
    00813 //
    00814 //        A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
    00815 //        If a platform requires absolutely no alignment, a value
    00816 //        of 1 should be specified ("align pointers on 1 byte boundaries").
    00817 //
    00818 inline size_t
    00819 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
    00820 {
    00821     //  Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
    00822     //  as needed to dictate alignment requirements on a
    00823     //  per-architecture basis. In the absense of that we
    00824     //  take an educated guess.
    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     //  Calculate current alignment of pointer
    00832     size_t current = ptrSize % alignment;
    00833
    00834     //  Adjust pointer alignment as needed
    00835     return (current == 0)
    00836          ? ptrSize
    00837          : (ptrSize + alignment - current);
    00838 }
    00839
    00840
    00841
    00842 // ---------------------------------------------------------------------------
    00843 //  XMLDeleter: Public Destructor
    00844 // ---------------------------------------------------------------------------
    00845 inline XMLDeleter::~XMLDeleter()
    00846 {
    00847 }
    00848
    00849 // ---------------------------------------------------------------------------
    00850 //  XMLDeleter: Hidden constructors and operators
    00851 // ---------------------------------------------------------------------------
    00852 inline XMLDeleter::XMLDeleter()
    00853 {
    00854 }
    00855
    00856 XERCES_CPP_NAMESPACE_END
    00857
    00858 #endif

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