?? platformutils.hpp
字號:
/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: PlatformUtils.hpp,v 1.27 2004/09/08 13:56:22 peiyongz Exp $ */#if !defined(PLATFORMUTILS_HPP)#define PLATFORMUTILS_HPP#include <xercesc/util/XMLException.hpp>#include <xercesc/util/PanicHandler.hpp>XERCES_CPP_NAMESPACE_BEGINclass XMLMsgLoader;class XMLNetAccessor;class XMLTransService;class MemoryManager;class XMLMutex;//// For internal use only//// This class provides a simple abstract API via which lazily evaluated// data can be cleaned up.//class XMLUTIL_EXPORT XMLDeleter{public : virtual ~XMLDeleter();protected : XMLDeleter();private : XMLDeleter(const XMLDeleter&); XMLDeleter& operator=(const XMLDeleter&);};/** * Utilities that must be implemented in a platform-specific way. * * This class contains methods that must be implemented in a platform * specific manner. The actual implementations of these methods are * available in the per-platform files indide <code>src/util/Platforms * </code>. */class XMLUTIL_EXPORT XMLPlatformUtils{public : /** @name Public Static Data */ //@{ /** The network accessor * * This is provided by the per-platform driver, so each platform can * choose what actual implementation it wants to use. The object must * be dynamically allocated. * * <i>Note that you may optionally, if your platform driver does not * install a network accessor, set it manually from your client code * after calling Initialize(). This works because this object is * not required during initialization, and only comes into play during * actual XML parsing.</i> */ static XMLNetAccessor* fgNetAccessor; /** The transcoding service. * * This is provided by the per platform driver, so each platform can * choose what implemenation it wants to use. When the platform * independent initialization code needs to get a transcoding service * object, it will call <code>makeTransService()</code> to ask the * per-platform code to create one. Only one transcoding service * object is reqeusted per-process, so it is shared and synchronized * among parser instances within that process. */ static XMLTransService* fgTransService; /** The Panic Handler * * This is the application provided panic handler. */ static PanicHandler* fgUserPanicHandler; /** The Panic Handler * * This is the default panic handler. */ static PanicHandler* fgDefaultPanicHandler; /** The configurable memory manager * * This is the pluggable memory manager. If it is not provided by an * application, a default implementation is used. */ static MemoryManager* fgMemoryManager; /** The array-allocating memory manager * * This memory manager always allocates memory by calling the * global new[] operator. It may be used to allocate memory * where such memory needs to be deletable by calling delete []. * Since this allocator is always guaranteed to do the same thing * there is no reason, nor facility, to override it. */ static MemoryManager* fgArrayMemoryManager; static XMLMutex* fgAtomicMutex; //@} /** @name Initialization amd Panic methods */ //@{ /** Perform per-process parser initialization * * Initialization <b>must</b> be called first in any client code. * * The locale is set iff the Initialize() is invoked for the very first time, * to ensure that each and every message loaders, in the process space, share * the same locale. * * All subsequent invocations of Initialize(), with a different locale, have * no effect on the message loaders, either instantiated, or to be instantiated. * * To set to a different locale, client application needs to Terminate() (or * multiple Terminate() in the case where multiple Initialize() have been invoked * before), followed by Initialize(new_locale). * * The default locale is "en_US". * * nlsHome: user specified location where MsgLoader retrieves error message files. * the discussion above with regard to locale, applies to this nlsHome * as well. * * panicHandler: application's panic handler, application owns this handler. * Application shall make sure that the plugged panic handler persists * through the call to XMLPlatformUtils::terminate(). * * memoryManager: plugged-in memory manager which is owned by user * applications. Applications must make sure that the * plugged-in memory manager persist through the call to * XMLPlatformUtils::terminate() */ static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale , const char* const nlsHome = 0 , PanicHandler* const panicHandler = 0 , MemoryManager* const memoryManager = 0); /** Perform per-process parser termination * * The termination call is currently optional, to aid those dynamically * loading the parser to clean up before exit, or to avoid spurious * reports from leak detectors. */ static void Terminate(); /** The panic mechanism. * * If, during initialization, we cannot even get far enough along * to get transcoding up or get message loading working, we call * this method.</p> * * Each platform can implement it however they want. This method will * delegate the panic handling to a user specified panic handler or * in the absence of it, the default panic handler. * * In case the default panic handler does not support a particular * platform, the platform specific panic hanlding shall be implemented * here </p>. * * @param reason The enumeration that defines the cause of the failure */ static void panic ( const PanicHandler::PanicReasons reason ); //@} /** @name File Methods */ //@{ /** Get the current file position * * This must be implemented by the per-platform driver, which should * use local file services to deterine the current position within * the passed file. * * Since the file API provided here only reads, if the host platform * supports separate read/write positions, only the read position is * of any interest, and hence should be the one returned. * * @param theFile The file handle * @param manager The MemoryManager to use to allocate objects */ static unsigned int curFilePos(FileHandle theFile , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** Closes the file handle * * This must be implemented by the per-platform driver, which should * use local file services to close the passed file handle, and to * destroy the passed file handle and any allocated data or system * resources it contains. * * @param theFile The file handle to close * @param manager The MemoryManager to use to allocate objects */ static void closeFile(FileHandle theFile , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** Returns the file size * * This must be implemented by the per-platform driver, which should * use local file services to determine the current size of the file * represented by the passed handle. * * @param theFile The file handle whose size you want * @param manager The MemoryManager to use to allocate objects * @return Returns the size of the file in bytes */ static unsigned int fileSize(FileHandle theFile , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** Opens the file * * This must be implemented by the per-platform driver, which should * use local file services to open passed file. If it fails, a * null handle pointer should be returned. * * @param fileName The string containing the name of the file * @param manager The MemoryManager to use to allocate objects * @return The file handle of the opened file */ static FileHandle openFile(const char* const fileName , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** Opens a named file * * This must be implemented by the per-platform driver, which should * use local file services to open the passed file. If it fails, a * null handle pointer should be returned. * * @param fileName The string containing the name of the file * @param manager The MemoryManager to use to allocate objects * @return The file handle of the opened file */ static FileHandle openFile(const XMLCh* const fileName , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** Open a named file to write * * This must be implemented by the per-platform driver, which should * use local file services to open passed file. If it fails, a * null handle pointer should be returned. * * @param fileName The string containing the name of the file * @param manager The MemoryManager to use to allocate objects * @return The file handle of the opened file */ static FileHandle openFileToWrite(const char* const fileName , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** Open a named file to write * * This must be implemented by the per-platform driver, which should
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -