source: NonGTP/Xerces/xerces/include/xercesc/util/PlatformUtils.hpp @ 358

Revision 358, 32.7 KB checked in by bittner, 19 years ago (diff)

xerces added

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