source: NonGTP/Xerces/xercesc/util/PlatformUtils.hpp @ 188

Revision 188, 33.7 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: PlatformUtils.hpp,v 1.24 2004/01/29 11:48:46 cargilld Exp $
59 */
60
61
62#if !defined(PLATFORMUTILS_HPP)
63#define PLATFORMUTILS_HPP
64
65#include <xercesc/util/XMLException.hpp>
66#include <xercesc/util/PanicHandler.hpp>
67
68XERCES_CPP_NAMESPACE_BEGIN
69
70class XMLMsgLoader;
71class XMLNetAccessor;
72class XMLTransService;
73class MemoryManager;
74class XMLMutex;
75
76//
77//  For internal use only
78//
79//  This class provides a simple abstract API via which lazily evaluated
80//  data can be cleaned up.
81//
82class XMLUTIL_EXPORT XMLDeleter
83{
84public :
85    virtual ~XMLDeleter();
86
87protected :
88    XMLDeleter();
89
90private :
91    XMLDeleter(const XMLDeleter&);
92    XMLDeleter& operator=(const XMLDeleter&);
93};
94
95
96/**
97  * Utilities that must be implemented in a platform-specific way.
98  *
99  * This class contains methods that must be implemented in a platform
100  * specific manner. The actual implementations of these methods are
101  * available in the per-platform files indide <code>src/util/Platforms
102  * </code>.
103  */
104class XMLUTIL_EXPORT XMLPlatformUtils
105{
106public :
107
108    /** @name Public Static Data */
109    //@{
110
111    /** The network accessor
112      *
113      * This is provided by the per-platform driver, so each platform can
114      * choose what actual implementation it wants to use. The object must
115      * be dynamically allocated.
116      *
117      * <i>Note that you may optionally, if your platform driver does not
118      * install a network accessor, set it manually from your client code
119      * after calling Initialize(). This works because this object is
120      * not required during initialization, and only comes into play during
121      * actual XML parsing.</i>
122      */
123    static XMLNetAccessor*      fgNetAccessor;
124
125    /** The transcoding service.
126      *
127      * This is provided by the per platform driver, so each platform can
128      * choose what implemenation it wants to use. When the platform
129      * independent initialization code needs to get a transcoding service
130      * object, it will call <code>makeTransService()</code> to ask the
131      * per-platform code to create one. Only one transcoding service
132      * object is reqeusted per-process, so it is shared and synchronized
133      * among parser instances within that process.
134      */
135    static XMLTransService*     fgTransService;
136
137    /** The Panic Handler
138      *
139      *   This is the application provided panic handler.
140      */
141    static PanicHandler*        fgUserPanicHandler;
142   
143    /** The Panic Handler
144      *
145      *   This is the default panic handler.
146      */   
147    static PanicHandler*        fgDefaultPanicHandler;
148
149    /** The configurable memory manager
150      *
151      *   This is the pluggable memory manager. If it is not provided by an
152      *   application, a default implementation is used.
153      */
154    static MemoryManager*       fgMemoryManager;
155   
156    /** The array-allocating memory manager
157      *
158      *   This memory manager always allocates memory by calling the
159      *   global new[] operator. It may be used to allocate memory
160      *   where such memory needs to be deletable by calling delete [].
161      *   Since this allocator is always guaranteed to do the same thing
162      *   there is no reason, nor facility, to override it.
163      */
164    static MemoryManager*       fgArrayMemoryManager;
165
166    static XMLMutex*            fgAtomicMutex;
167   
168    //@}
169
170
171    /** @name Initialization amd Panic methods */
172    //@{
173
174    /** Perform per-process parser initialization
175      *
176      * Initialization <b>must</b> be called first in any client code.
177      *
178      * The locale is set iff the Initialize() is invoked for the very first time,
179      * to ensure that each and every message loaders, in the process space, share
180      * the same locale.
181      *
182      * All subsequent invocations of Initialize(), with a different locale, have
183      * no effect on the message loaders, either instantiated, or to be instantiated.
184      *
185      * To set to a different locale, client application needs to Terminate() (or
186      * multiple Terminate() in the case where multiple Initialize() have been invoked
187      * before), followed by Initialize(new_locale).
188      *
189      * The default locale is "en_US".
190      *
191      * nlsHome: user specified location where MsgLoader retrieves error message files.
192      *          the discussion above with regard to locale, applies to this nlsHome
193      *          as well.
194      *
195      * panicHandler: application's panic handler, application owns this handler.
196      *               Application shall make sure that the plugged panic handler persists
197      *               through the call to XMLPlatformUtils::terminate().       
198      *
199      * memoryManager: plugged-in memory manager which is owned by user
200      *                applications. Applications must make sure that the
201      *                plugged-in memory manager persisit through the call to
202      *                XMLPlatformUtils::terminate()
203      */
204    static void Initialize(const char*          const locale = XMLUni::fgXercescDefaultLocale
205                         , const char*          const nlsHome = 0
206                         ,       PanicHandler*  const panicHandler = 0
207                         ,       MemoryManager* const memoryManager = 0);
208
209    /** Perform per-process parser termination
210      *
211      * The termination call is currently optional, to aid those dynamically
212      * loading the parser to clean up before exit, or to avoid spurious
213      * reports from leak detectors.
214      */
215    static void Terminate();
216
217    /** The panic mechanism.
218      *
219      * If, during initialization, we cannot even get far enough along
220      * to get transcoding up or get message loading working, we call
221      * this method.</p>
222      *
223      * Each platform can implement it however they want. This method will
224      * delegate the panic handling to a user specified panic handler or
225      * in the absence of it, the default panic handler.
226      *
227      * In case the default panic handler does not support a particular
228      * platform, the platform specific panic hanlding shall be implemented
229      * here </p>.
230      *
231      * @param reason The enumeration that defines the cause of the failure
232      */
233    static void panic
234    (
235        const   PanicHandler::PanicReasons    reason
236    );
237   
238    //@}
239
240    /** @name File Methods */
241    //@{
242
243    /** Get the current file position
244      *
245      * This must be implemented by the per-platform driver, which should
246      * use local file services to deterine the current position within
247      * the passed file.
248      *
249      * Since the file API provided here only reads, if the host platform
250      * supports separate read/write positions, only the read position is
251      * of any interest, and hence should be the one returned.
252      *
253      * @param theFile The file handle
254      */
255    static unsigned int curFilePos(FileHandle theFile
256        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
257
258    /** Closes the file handle
259      *
260      * This must be implemented by the per-platform driver, which should
261      * use local file services to close the passed file handle, and to
262      * destroy the passed file handle and any allocated data or system
263      * resources it contains.
264      *
265      * @param theFile The file handle to close
266      */
267    static void closeFile(FileHandle theFile
268        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
269
270    /** Returns the file size
271      *
272      * This must be implemented by the per-platform driver, which should
273      * use local file services to determine the current size of the file
274      * represented by the passed handle.
275      *
276      * @param theFile The file handle whose size you want
277      *
278      * @return Returns the size of the file in bytes
279      */
280    static unsigned int fileSize(FileHandle theFile
281        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
282
283    /** Opens the file
284      *
285      * This must be implemented by the per-platform driver, which should
286      * use local file services to open passed file. If it fails, a
287      * null handle pointer should be returned.
288      *
289      * @param fileName The string containing the name of the file
290      *
291      * @return The file handle of the opened file
292      */
293    static FileHandle openFile(const char* const fileName
294        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
295
296    /** Opens a named file
297      *
298      * This must be implemented by the per-platform driver, which should
299      * use local file services to open the passed file. If it fails, a
300      * null handle pointer should be returned.
301      *
302      * @param fileName The string containing the name of the file
303      *
304      * @return The file handle of the opened file
305      */
306    static FileHandle openFile(const XMLCh* const fileName
307        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
308
309    /** Open a named file to write
310      *
311      * This must be implemented by the per-platform driver, which should
312      * use local file services to open passed file. If it fails, a
313      * null handle pointer should be returned.
314      *
315      * @param fileName The string containing the name of the file
316      *
317      * @return The file handle of the opened file
318      */
319    static FileHandle openFileToWrite(const char* const fileName
320        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
321
322    /** Open a named file to write
323      *
324      * This must be implemented by the per-platform driver, which should
325      * use local file services to open the passed file. If it fails, a
326      * null handle pointer should be returned.
327      *
328      * @param fileName The string containing the name of the file
329      *
330      * @return The file handle of the opened file
331      */
332    static FileHandle openFileToWrite(const XMLCh* const fileName
333        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
334
335    /** Opens the standard input as a file
336      *
337      * This must be implemented by the per-platform driver, which should
338      * use local file services to open a handle to the standard input.
339      * It should be a copy of the standard input handle, since it will
340      * be closed later!
341      *
342      * @return The file handle of the standard input stream
343      */
344    static FileHandle openStdInHandle(MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
345
346    /** Reads the file buffer
347      *
348      * This must be implemented by the per-platform driver, which should
349      * use local file services to read up to 'toRead' bytes of data from
350      * the passed file, and return those bytes in the 'toFill' buffer. It
351      * is not an error not to read the requested number of bytes. When the
352      * end of file is reached, zero should be returned.
353      *
354      * @param theFile The file handle to be read from.
355      * @param toRead The maximum number of byte to read from the current
356      * position
357      * @param toFill The byte buffer to fill
358      *
359      * @return Returns the number of bytes read from the stream or file
360      */
361    static unsigned int readFileBuffer
362    (
363                FileHandle      theFile
364        , const unsigned int    toRead
365        ,       XMLByte* const  toFill
366        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
367    );
368
369    /** Writes the buffer to the file
370      *
371      * This must be implemented by the per-platform driver, which should
372      * use local file services to write up to 'toWrite' bytes of data to
373      * the passed file. Unless exception raised by local file services,
374      * 'toWrite' bytes of data is to be written to the passed file.
375      *
376      * @param theFile The file handle to be written to.
377      * @param toWrite The maximum number of byte to write from the current
378      * position
379      * @param toFlush The byte buffer to flush
380      *
381      * @return void
382      */
383    static void writeBufferToFile
384    (
385          FileHandle     const  theFile
386        , long                  toWrite
387        , const XMLByte* const  toFlush
388        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
389    );
390
391    /** Resets the file handle
392      *
393      * This must be implemented by the per-platform driver which will use
394      * local file services to reset the file position to the start of the
395      * the file.
396      *
397      * @param theFile The file handle that you want to reset
398      */
399    static void resetFile(FileHandle theFile
400        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
401
402    //@}
403
404
405    /** @name File System Methods */
406    //@{
407    /** Gets the full path from a relative path
408      *
409      * This must be implemented by the per-platform driver. It should
410      * complete a relative path using the 'current directory', or whatever
411      * the local equivalent of a current directory is. If the passed
412      * source path is actually fully qualified, then a straight copy of it
413      * will be returned.
414      *
415      * @param srcPath The path of the file for which you want the full path
416      *
417      * @param manager Pointer to the memory manager to be used to
418      *                allocate objects.
419      *
420      * @return Returns the fully qualified path of the file name including
421      *         the file name. This is dyanmically allocated and must be
422      *         deleted  by the caller when its no longer needed! The memory
423      *         returned will beallocated using the static memory manager, if
424      *         user do not supply a memory manager. Users then need to make
425      *         sure to use either the default or user specific memory manager
426      *         to deallocate the memory.
427      */
428    static XMLCh* getFullPath
429    (
430        const XMLCh* const srcPath
431        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
432    );
433
434    /** Gets the current working directory
435      *
436      * This must be implemented by the per-platform driver. It returns
437      * the current working directory is.
438      *
439      * @return Returns the current working directory.
440      *         This is dyanmically allocated and must be deleted
441      *         by the caller when its no longer needed! The memory returned
442      *         will be allocated using the static memory manager, if users
443      *         do not supply a memory manager. Users then need to make sure
444      *         to use either the default or user specific memory manager to
445      *         deallocate the memory.
446      */
447    static XMLCh* getCurrentDirectory
448    (
449        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
450    );
451
452    /** Check if a charater is a slash
453      *
454      * This must be implemented by the per-platform driver.
455      *
456      * @param c the character to be examined
457      *
458      * @return true  if the character examined is a slash
459      *         false otherwise
460      */
461    static inline bool isAnySlash(XMLCh c);
462   
463    /** Remove occurences of the pair of dot slash
464      *
465      * To remove the sequence, dot slash if it is part of the sequence,
466      * slash dot slash.
467      *
468      * @param srcPath The path for which you want to remove the dot slash sequence.
469      *
470      * @return
471      */
472    static void   removeDotSlash(XMLCh* const srcPath
473        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
474
475    /** Remove occurences of the dot dot slash
476      *
477      * To remove the sequence, slash dot dot slash and its preceding path segment
478      * if and only if the preceding path segment is not slash dot dot slash.
479      *
480      * @param srcPath The path for which you want to remove the slash dot
481      *        dot slash sequence and its preceding path segment.
482      *
483      * @return
484      */
485    static void   removeDotDotSlash(XMLCh* const srcPath
486        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
487
488    /** Determines if a path is relative or absolute
489      *
490      * This must be implemented by the per-platform driver, which should
491      * determine whether the passed path is relative or not. The concept
492      * of relative and absolute might be... well relative on different
493      * platforms. But, as long as the determination is made consistently
494      * and in coordination with the weavePaths() method, it should work
495      * for any platform.
496      *
497      * @param toCheck The file name which you want to check
498      *
499      * @return Returns true if the filename appears to be relative
500      */
501    static bool isRelative(const XMLCh* const toCheck
502        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
503        );
504
505    /** Utility to join two paths
506      *
507      * This must be implemented by the per-platform driver, and should
508      * weave the relative path part together with the base part and return
509      * a new path that represents this combination.
510      *
511      * If the relative part turns out to be fully qualified, it will be
512      * returned as is. If it is not, then it will be woven onto the
513      * passed base path, by removing one path component for each leading
514      * "../" (or whatever is the equivalent in the local system) in the
515      * relative path.
516      *
517      * @param basePath The string containing the base path
518      * @param relativePath The string containing the relative path
519      *
520      * @return Returns a string containing the 'woven' path. It should
521      * be dynamically allocated and becomes the responsibility of the
522      * caller to delete.
523      */
524    static XMLCh* weavePaths
525    (
526        const   XMLCh* const    basePath
527        , const XMLCh* const    relativePath
528        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
529    );
530    //@}
531
532    /** @name Timing Methods */
533    //@{
534
535    /** Gets the system time in milliseconds
536      *
537      * This must be implemented by the per-platform driver, which should
538      * use local services to return the current value of a running
539      * millisecond timer. Note that the value returned is only as accurate
540      * as the millisecond time of the underyling host system.
541      *
542      * @return Returns the system time as an unsigned long
543      */
544    static unsigned long getCurrentMillis();
545    //@}
546
547    /** @name Mutex Methods */
548    //@{
549
550    /** Closes a mutex handle
551      *
552      * Each per-platform driver must implement this. Only it knows what
553      * the actual content of the passed mutex handle is.
554      *
555      * @param mtxHandle The mutex handle that you want to close
556      */
557    static void closeMutex(void* const mtxHandle);
558
559    /** Locks a mutex handle
560      *
561      * Each per-platform driver must implement this. Only it knows what
562      * the actual content of the passed mutex handle is.
563      *
564      * @param mtxHandle The mutex handle that you want to lock
565      */
566    static void lockMutex(void* const mtxHandle);
567
568    /** Make a new mutex
569      *
570      * Each per-platform driver must implement this. Only it knows what
571      * the actual content of the passed mutex handle is. The returned
572      * handle pointer will be eventually passed to closeMutex() which is
573      * also implemented by the platform driver.
574      */
575    static void* makeMutex();
576
577    /** Unlocks a mutex
578      *
579      * Each per-platform driver must implement this. Only it knows what
580      * the actual content of the passed mutex handle is.
581      *
582      * Note that, since the underlying system synchronization services
583      * are used, Xerces cannot guarantee that lock/unlock operations are
584      * correctly enforced on a per-thread basis or that incorrect nesting
585      * of lock/unlock operations will be caught.
586      *
587      * @param mtxHandle The mutex handle that you want to unlock
588      */
589    static void unlockMutex(void* const mtxHandle);
590
591    //@}
592
593
594    /** @name External Message Support */
595    //@{
596
597    /** Loads the message set from among the available domains
598      *
599      * The returned object must be dynamically allocated and the caller
600      * becomes responsible for cleaning it up.
601      *
602      * @param msgDomain The message domain which you want to load
603      */
604    static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain);
605
606    //@}
607
608    /** @name Miscellaneous synchronization methods */
609    //@{
610
611    /** Conditionally updates or returns a single word variable atomically
612      *
613      * This must be implemented by the per-platform driver. The
614      * compareAndSwap subroutine performs an atomic operation which
615      * compares the contents of a single word variable with a stored old
616      * value. If the values are equal, a new value is stored in the single
617      * word variable and TRUE is returned; otherwise, the old value is set
618      * to the current value of the single word variable and FALSE is
619      * returned.
620      *
621      * The compareAndSwap subroutine is useful when a word value must be
622      * updated only if it has not been changed since it was last read.
623      *
624      * Note: The word containing the single word variable must be aligned
625      * on a full word boundary.
626      *
627      * @param toFill Specifies the address of the single word variable
628      * @param newValue Specifies the new value to be conditionally assigned
629      * to the single word variable.
630      * @param toCompare Specifies the address of the old value to be checked
631      * against (and conditionally updated with) the value of the single word
632      * variable.
633      *
634      * @return Returns the new value assigned to the single word variable
635      */
636    static void* compareAndSwap
637    (
638                void**      toFill
639        , const void* const newValue
640        , const void* const toCompare
641    );
642
643    //@}
644
645
646    /** @name Atomic Increment and Decrement */
647    //@{
648
649    /** Increments a single word variable atomically.
650      *
651      * This must be implemented by the per-platform driver. The
652      * atomicIncrement subroutine increments one word in a single atomic
653      * operation. This operation is useful when a counter variable is shared
654      * between several threads or processes. When updating such a counter
655      * variable, it is important to make sure that the fetch, update, and
656      * store operations occur atomically (are not interruptible).
657      *
658      * @param location Specifies the address of the word variable to be
659      * incremented.
660      *
661      * @return The function return value is positive if the result of the
662      * operation was positive. Zero if the result of the operation was zero.
663      * Negative if the result of the operation was negative. Except for the
664      * zero case, the value returned may differ from the actual result of
665      * the operation - only the sign and zero/nonzero state is guaranteed
666      * to be correct.
667      */
668    static int atomicIncrement(int& location);
669
670    /** Decrements a single word variable atomically.
671      *
672      * This must be implemented by the per-platform driver. The
673      * atomicDecrement subroutine increments one word in a single atomic
674      * operation. This operation is useful when a counter variable is shared
675      * between several threads or processes. When updating such a counter
676      * variable, it is important to make sure that the fetch, update, and
677      * store operations occur atomically (are not interruptible).
678      *
679      * @param location Specifies the address of the word variable to be
680      * decremented.
681      *
682      * @return The function return value is positive if the result of the
683      * operation was positive. Zero if the result of the operation was zero.
684      * Negative if the result of the operation was negative. Except for the
685      * zero case, the value returned may differ from the actual result of the
686      * operation - only the sign and zero/nonzero state is guaranteed to be
687      * correct.
688      */
689    static int atomicDecrement(int& location);
690
691    //@}
692
693    /** @name NEL Character Handling  */
694    //@{
695        /**
696      * This function enables the recognition of NEL(0x85) char and LSEP (0x2028) as newline chars
697      * which is disabled by default.
698      * It is only called once per process. Once it is set, any subsequent calls
699      * will result in exception being thrown.
700      *
701      * Note: 1. Turning this option on will make the parser non compliant to XML 1.0.
702      *       2. This option has no effect to document conforming to XML 1.1 compliant,
703      *          which always recognize these two chars (0x85 and 0x2028) as newline characters.
704      *
705      */
706    static void recognizeNEL(bool state
707        , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager);
708
709    /**
710      * Return the value of fgNEL flag.
711      */
712    static bool isNELRecognized();
713    //@}
714
715    /** @name Strict IANA Encoding Checking */
716    //@{
717        /**
718      * This function enables/disables strict IANA encoding names checking.
719      *
720      * The strict checking is disabled by default.
721      *
722      * @param state If true, a strict IANA encoding name check is performed,
723      *              otherwise, no checking.
724      *
725      */
726    static void strictIANAEncoding(const bool state);
727
728    /**
729      * Returns whether a strict IANA encoding name check is enabled or
730      * disabled.
731      */
732    static bool isStrictIANAEncoding();
733    //@}
734               
735    /**
736      * Aligns the specified pointer per platform block allocation
737          * requirements.
738          *
739          *     The results of this function may be altered by defining
740          * XML_PLATFORM_NEW_BLOCK_ALIGNMENT.
741          */
742        static inline size_t alignPointerForNewBlockAllocation(size_t ptrSize);
743
744private :
745    // -----------------------------------------------------------------------
746    //  Unimplemented constructors and operators
747    // -----------------------------------------------------------------------
748    XMLPlatformUtils();
749
750    /** @name Private static methods */
751    //@{
752
753    /** Loads a message set from the available domains
754      *
755      * @param msgDomain The message domain containing the message to be
756      * loaded
757      */
758    static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain);
759
760    /** Creates a net accessor object.
761      *
762      * Each per-platform driver must implement this method. However,
763      * having a Net Accessor is optional and this method can return a
764      * null pointer if remote access via HTTP and FTP URLs is not required.
765      *
766      * @return An object derived from XMLNetAccessor. It must be dynamically
767      *         allocated, since it will be deleted later.
768      */
769    static XMLNetAccessor* makeNetAccessor();
770
771    /** Creates a Transoding service
772      *
773      * Each per-platform driver must implement this method and return some
774      * derivative of the XMLTransService class. This object serves as the
775      * transcoder factory for this process. The object must be dynamically
776      * allocated and the caller is responsible for cleaning it up.
777      *
778      * @return A dynamically allocated object of some class derived from
779      *         the XMLTransService class.
780      */
781    static XMLTransService* makeTransService();
782
783    /** Does initialization for a particular platform
784      *
785      * Each per-platform driver must implement this to do any low level
786      * system initialization required. It <b>cannot</b> use any XML
787      * parser or utilities services!
788      */
789    static void platformInit();
790
791    /** Does termination for a particular platform
792      *
793      * Each per-platform driver must implement this to do any low level
794      * system resource cleanup required. It <b>cannot</b> use any XML
795      * parser or utilities services!
796      */
797    static void platformTerm();
798
799    /** Search for sequence, slash dot dot slash
800      *
801      * @param srcPath the path to search
802      *
803      * @return   the position of the first occurence of slash dot dot slash
804      *            -1 if no such sequence is found
805      */
806    static int  searchSlashDotDotSlash(XMLCh* const srcPath);
807
808    //@}
809
810    /** @name Private static methods */
811    //@{
812
813    /**
814      * Indicates whether the memory manager was supplied by the user
815      * or not. Users own the memory manager, and if none is supplied,
816      * Xerces uses a default one that it owns and is responsible for
817      * deleting in Terminate().
818      */
819    static bool fgMemMgrAdopted;
820
821    //@}
822};
823
824
825MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT)
826
827
828// ---------------------------------------------------------------------------
829//  XMLPlatformUtils: alignPointerForNewBlockAllocation
830// ---------------------------------------------------------------------------
831//  Calculate alignment required by platform for a new
832//      block allocation. We use this in our custom allocators
833//      to ensure that returned blocks are properly aligned.
834//  Note that, although this will take a pointer and return the position
835//  at which it should be placed for correct alignment, in our code
836//  we normally use size_t parameters to discover what the alignment
837//  of header blocks should be.  Thus, if this is to be
838//  used for the former purpose, to make compilers happy
839//  some casting will be necessary - neilg.
840//
841//  Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a
842//        per-architecture basis to dictate the alignment requirements
843//        of the architecture. In the absense of this specification,
844//        this routine guesses at the correct alignment value.
845//
846//        A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal.
847//        If a platform requires absolutely no alignment, a value
848//        of 1 should be specified ("align pointers on 1 byte boundaries").
849//
850inline size_t
851XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize)
852{
853        //      Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined
854        //      as needed to dictate alignment requirements on a
855        //      per-architecture basis. In the absense of that we
856        //      take an educated guess.
857        #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT
858                size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT;
859        #else
860                size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
861        #endif
862       
863        //      Calculate current alignment of pointer
864        size_t current = ptrSize % alignment;
865       
866        //      Adjust pointer alignment as needed
867        return (current == 0)
868                 ? ptrSize
869                 : (ptrSize + alignment - current);
870}
871
872
873
874// ---------------------------------------------------------------------------
875//  XMLDeleter: Public Destructor
876// ---------------------------------------------------------------------------
877inline XMLDeleter::~XMLDeleter()
878{
879}
880
881// ---------------------------------------------------------------------------
882//  XMLDeleter: Hidden constructors and operators
883// ---------------------------------------------------------------------------
884inline XMLDeleter::XMLDeleter()
885{
886}
887
888XERCES_CPP_NAMESPACE_END
889
890#endif
Note: See TracBrowser for help on using the repository browser.