1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 /* 21 * XSEC 22 * 23 * XSECAutoPtr := internal classes for RAII handling of transcoded data 24 * 25 * Author(s): Scott Cantor 26 * 27 * $Id:$ 28 * 29 */ 30 31 32 #ifndef XSECAUTOPTR_INCLUDE 33 #define XSECAUTOPTR_INCLUDE 34 35 #include <xsec/framework/XSECDefs.hpp> 36 #include <xercesc/util/XMLString.hpp> 37 38 XSEC_USING_XERCES(XMLString); 39 40 /** 41 * \addtogroup internal 42 * @{ 43 */ 44 45 /** 46 * A minimal auto_ptr-like class that can copy or transcode a buffer into 47 * the local code page and free the result automatically. 48 * 49 * Needed because a standard auto_ptr would use delete on the resulting 50 * pointer. 51 */ 52 class XSECAutoPtrChar 53 { 54 XSECAutoPtrChar(const XSECAutoPtrChar&); 55 XSECAutoPtrChar& operator=(const XSECAutoPtrChar&); 56 public: XSECAutoPtrChar()57 XSECAutoPtrChar() : m_buf(NULL) { 58 } 59 XSECAutoPtrChar(const XMLCh * src)60 XSECAutoPtrChar(const XMLCh* src) : m_buf(xercesc::XMLString::transcode(src)) { 61 } 62 XSECAutoPtrChar(const char * src)63 XSECAutoPtrChar(const char* src) : m_buf(xercesc::XMLString::replicate(src)) { 64 } 65 ~XSECAutoPtrChar()66 ~XSECAutoPtrChar() { 67 XSEC_RELEASE_XMLCH(m_buf); 68 } 69 get() const70 const char* get() const { 71 return m_buf; 72 } 73 release()74 char* release() { 75 char* temp=m_buf; m_buf=NULL; return temp; 76 } 77 78 private: 79 char* m_buf; 80 }; 81 82 /** 83 * A minimal auto_ptr-like class that can copy or transcode a buffer into 84 * 16-bit Unicode and free the result automatically. 85 * 86 * Needed because a standard auto_ptr would use delete on the resulting 87 * pointer. 88 */ 89 class XSECAutoPtrXMLCh 90 { 91 XSECAutoPtrXMLCh(const XSECAutoPtrXMLCh&); 92 XSECAutoPtrXMLCh& operator=(const XSECAutoPtrXMLCh&); 93 public: XSECAutoPtrXMLCh()94 XSECAutoPtrXMLCh() : m_buf(NULL) { 95 } 96 XSECAutoPtrXMLCh(const char * src)97 XSECAutoPtrXMLCh(const char* src) : m_buf(xercesc::XMLString::transcode(src)) { 98 } 99 XSECAutoPtrXMLCh(const XMLCh * src)100 XSECAutoPtrXMLCh(const XMLCh* src) : m_buf(xercesc::XMLString::replicate(src)) { 101 } 102 ~XSECAutoPtrXMLCh()103 ~XSECAutoPtrXMLCh() { 104 XSEC_RELEASE_XMLCH(m_buf); 105 } 106 get() const107 const XMLCh* get() const { 108 return m_buf; 109 } 110 release()111 XMLCh* release() { 112 XMLCh* temp=m_buf; m_buf=NULL; return temp; 113 } 114 115 private: 116 XMLCh* m_buf; 117 }; 118 119 /** @} */ 120 121 #endif /* XSECAUTOPTR_INCLUDE */ 122 123