source: icXML/icXML-devel/src/xercesc/framework/MemBufInputSource.cpp @ 2732

Last change on this file since 2732 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 3.4 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: MemBufInputSource.cpp 553941 2007-07-06 16:14:22Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/util/BinMemInputStream.hpp>
27#include <xercesc/framework/MemBufInputSource.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31// ---------------------------------------------------------------------------
32//  MemBufInputSource: Constructors and Destructor
33// ---------------------------------------------------------------------------
34MemBufInputSource::MemBufInputSource( const XMLByte* const  srcDocBytes
35                                    , const XMLSize_t       byteCount
36                                    , const XMLCh* const    bufId
37                                    , const bool            adoptBuffer
38                                    , MemoryManager* const  manager) :
39    InputSource(bufId, manager)
40    , fAdopted(adoptBuffer)
41    , fByteCount(byteCount)
42    , fCopyBufToStream(true)
43    , fSrcBytes(srcDocBytes)
44{
45}
46
47MemBufInputSource::MemBufInputSource( const XMLByte* const  srcDocBytes
48                                    , const XMLSize_t       byteCount
49                                    , const char* const     bufId
50                                    , const bool            adoptBuffer
51                                    , MemoryManager* const  manager) :
52    InputSource(bufId, manager)
53    , fAdopted(adoptBuffer)
54    , fByteCount(byteCount)
55    , fCopyBufToStream(true)
56    , fSrcBytes(srcDocBytes)
57{
58}
59
60MemBufInputSource::~MemBufInputSource()
61{
62    if (fAdopted)
63        delete [] (XMLByte*)fSrcBytes;
64}
65
66void MemBufInputSource::resetMemBufInputSource(const XMLByte* const  srcDocBytes
67                                             , const XMLSize_t       byteCount)
68{
69    fByteCount = byteCount;
70    fSrcBytes  = srcDocBytes;
71}
72
73// ---------------------------------------------------------------------------
74//  MemBufInputSource: InputSource interface implementation
75// ---------------------------------------------------------------------------
76BinInputStream* MemBufInputSource::makeStream() const
77{
78    //
79    //  Create a memory input stream over our buffer. According to our
80    //  fCopyBufToStream flag, we either tell it to copy the buffer or to
81    //  just reference it.
82    //
83    return new (getMemoryManager()) BinMemInputStream
84    (
85        fSrcBytes
86        , fByteCount
87        , fCopyBufToStream ? BinMemInputStream::BufOpt_Copy
88                           : BinMemInputStream::BufOpt_Reference
89        , getMemoryManager()
90    );
91}
92
93XERCES_CPP_NAMESPACE_END
94
Note: See TracBrowser for help on using the repository browser.