http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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,v 1.27 2004/09/08 13:56:22 peiyongz Exp $
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 
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     //  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 
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 //  XMLPlatformUtils: alignPointerForNewBlockAllocation
00795 // ---------------------------------------------------------------------------
00796 //  Calculate alignment required by platform for a new
00797 //  block allocation. We use this in our custom allocators
00798 //  to ensure that returned blocks are properly aligned.
00799 //  Note that, although this will take a pointer and return the position
00800 //  at which it should be placed for correct alignment, in our code
00801 //  we normally use size_t parameters to discover what the alignment
00802 //  of header blocks should be.  Thus, if this is to be
00803 //  used for the former purpose, to make compilers happy
00804 //  some casting will be necessary - neilg.
00805 //
00806 //  Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
00807 //        per-architecture basis to dictate the alignment requirements
00808 //        of the architecture. In the absense of this specification,
00809 //        this routine guesses at the correct alignment value.
00810 //
00811 //        A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
00812 //        If a platform requires absolutely no alignment, a value
00813 //        of 1 should be specified ("align pointers on 1 byte boundaries").
00814 //
00815 inline size_t
00816 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
00817 {
00818     //  Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
00819     //  as needed to dictate alignment requirements on a
00820     //  per-architecture basis. In the absense of that we
00821     //  take an educated guess.
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     //  Calculate current alignment of pointer
00829     size_t current = ptrSize % alignment;
00830     
00831     //  Adjust pointer alignment as needed
00832     return (current == 0)
00833          ? ptrSize
00834          : (ptrSize + alignment - current);
00835 }
00836 
00837 
00838 
00839 // ---------------------------------------------------------------------------
00840 //  XMLDeleter: Public Destructor
00841 // ---------------------------------------------------------------------------
00842 inline XMLDeleter::~XMLDeleter()
00843 {
00844 }
00845 
00846 // ---------------------------------------------------------------------------
00847 //  XMLDeleter: Hidden constructors and operators
00848 // ---------------------------------------------------------------------------
00849 inline XMLDeleter::XMLDeleter()
00850 {
00851 }
00852 
00853 XERCES_CPP_NAMESPACE_END
00854 
00855 #endif


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