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  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 1999, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Id: PlatformUtils.hpp,v 1.24 2004/01/29 11:48:46 cargilld Exp $
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 //  For internal use only
00078 //
00079 //  This class provides a simple abstract API via which lazily evaluated
00080 //  data can be cleaned up.
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     //  Unimplemented constructors and operators
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 //  XMLPlatformUtils: alignPointerForNewBlockAllocation
00830 // ---------------------------------------------------------------------------
00831 //  Calculate alignment required by platform for a new
00832 //  block allocation. We use this in our custom allocators
00833 //  to ensure that returned blocks are properly aligned.
00834 //  Note that, although this will take a pointer and return the position
00835 //  at which it should be placed for correct alignment, in our code
00836 //  we normally use size_t parameters to discover what the alignment
00837 //  of header blocks should be.  Thus, if this is to be
00838 //  used for the former purpose, to make compilers happy
00839 //  some casting will be necessary - neilg.
00840 //
00841 //  Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
00842 //        per-architecture basis to dictate the alignment requirements
00843 //        of the architecture. In the absense of this specification,
00844 //        this routine guesses at the correct alignment value.
00845 //
00846 //        A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
00847 //        If a platform requires absolutely no alignment, a value
00848 //        of 1 should be specified ("align pointers on 1 byte boundaries").
00849 //
00850 inline size_t
00851 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
00852 {
00853     //  Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
00854     //  as needed to dictate alignment requirements on a
00855     //  per-architecture basis. In the absense of that we
00856     //  take an educated guess.
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     //  Calculate current alignment of pointer
00864     size_t current = ptrSize % alignment;
00865     
00866     //  Adjust pointer alignment as needed
00867     return (current == 0)
00868          ? ptrSize
00869          : (ptrSize + alignment - current);
00870 }
00871 
00872 
00873 
00874 // ---------------------------------------------------------------------------
00875 //  XMLDeleter: Public Destructor
00876 // ---------------------------------------------------------------------------
00877 inline XMLDeleter::~XMLDeleter()
00878 {
00879 }
00880 
00881 // ---------------------------------------------------------------------------
00882 //  XMLDeleter: Hidden constructors and operators
00883 // ---------------------------------------------------------------------------
00884 inline XMLDeleter::XMLDeleter()
00885 {
00886 }
00887 
00888 XERCES_CPP_NAMESPACE_END
00889 
00890 #endif


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