source: icXML/icXML-devel/src/icxercesc/util/PlatformUtils.hpp @ 2720

Last change on this file since 2720 was 2720, checked in by cameron, 6 years ago

Initial check-in of icXML 0.8 source files

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