[2674] | 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: XMLRegisterCleanup.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #if !defined(XMLREGISTERCLEANUP_HPP) |
---|
| 23 | #define XMLREGISTERCLEANUP_HPP |
---|
| 24 | |
---|
| 25 | #include <xercesc/util/Mutexes.hpp> |
---|
| 26 | |
---|
| 27 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 28 | |
---|
| 29 | // |
---|
| 30 | // For internal use only. |
---|
| 31 | // |
---|
| 32 | // This class is used by the platform utilities class to support |
---|
| 33 | // reinitialisation of global/static data which is lazily created. |
---|
| 34 | // Since that data is widely spread out the platform utilities |
---|
| 35 | // class cannot know about them directly. So, the code that creates such |
---|
| 36 | // objects creates an registers a cleanup for the object. The platform |
---|
| 37 | // termination call will iterate the list and delete the objects. |
---|
| 38 | // |
---|
| 39 | // N.B. These objects need to be statically allocated. I couldn't think |
---|
| 40 | // of a neat way of ensuring this - can anyone else? |
---|
| 41 | |
---|
| 42 | class XMLUTIL_EXPORT XMLRegisterCleanup |
---|
| 43 | { |
---|
| 44 | public : |
---|
| 45 | // The cleanup function to be called on XMLPlatformUtils::Terminate() |
---|
| 46 | typedef void (*XMLCleanupFn)(); |
---|
| 47 | |
---|
| 48 | void doCleanup(); |
---|
| 49 | |
---|
| 50 | // This function is called during initialisation of static data to |
---|
| 51 | // register a function to be called on XMLPlatformUtils::Terminate. |
---|
| 52 | // It gives an object that uses static data an opportunity to reset |
---|
| 53 | // such data. |
---|
| 54 | void registerCleanup(XMLCleanupFn cleanupFn); |
---|
| 55 | |
---|
| 56 | // This function can be called either from XMLPlatformUtils::Terminate |
---|
| 57 | // to state that the cleanup has been performed and should not be |
---|
| 58 | // performed again, or from code that you have written that determines |
---|
| 59 | // that cleanup is no longer necessary. |
---|
| 60 | void unregisterCleanup(); |
---|
| 61 | |
---|
| 62 | // The default constructor sets a state that ensures that this object |
---|
| 63 | // will do nothing |
---|
| 64 | XMLRegisterCleanup(); |
---|
| 65 | |
---|
| 66 | private: |
---|
| 67 | // ----------------------------------------------------------------------- |
---|
| 68 | // Unimplemented constructors and operators |
---|
| 69 | // ----------------------------------------------------------------------- |
---|
| 70 | XMLRegisterCleanup(const XMLRegisterCleanup&); |
---|
| 71 | XMLRegisterCleanup& operator=(const XMLRegisterCleanup&); |
---|
| 72 | |
---|
| 73 | // This is the cleanup function to be called |
---|
| 74 | XMLCleanupFn m_cleanupFn; |
---|
| 75 | |
---|
| 76 | // These are list pointers to the next/prev cleanup function to be called |
---|
| 77 | XMLRegisterCleanup *m_nextCleanup, *m_prevCleanup; |
---|
| 78 | |
---|
| 79 | // This function reinitialises the object to the default state |
---|
| 80 | void resetCleanup(); |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | XERCES_CPP_NAMESPACE_END |
---|
| 84 | |
---|
| 85 | #endif |
---|