fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Base / OSGIOFileTypeBase.cpp
blobf7d9caf164a43d711881497345a389b573e51e27
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2008 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include "OSGIOFileTypeBase.h"
41 OSG_BEGIN_NAMESPACE
43 /*-------------------------------------------------------------------------*/
44 /* IOFileTypeBase::IOOption */
45 /*-------------------------------------------------------------------------*/
47 IOFileTypeBase::IOOption::IOOption(void)
49 : optName (),
50 optValue()
52 // nothing to do
55 IOFileTypeBase::IOOption::IOOption(IOOption const &other)
57 : optName (other.optName ),
58 optValue(other.optValue)
60 // nothing to do
63 IOFileTypeBase::IOOption::IOOption(
64 const std::string &name, const std::string &value)
66 : optName (name ),
67 optValue(value)
69 // nothing to do
72 /*-------------------------------------------------------------------------*/
73 /* IOFileTypeBase */
74 /*-------------------------------------------------------------------------*/
76 /*-------------------------------------------------------------------------*/
77 /* Flags */
79 UInt32
80 IOFileTypeBase::getFlags(void) const
82 return _flags;
85 /*-------------------------------------------------------------------------*/
86 /* Option Handling */
88 /*! Pushes the current options onto the option stack. If \c copyTop is \c true
89 a copy of the current options is used as the new current options, otherwise
90 an empty options set is used.
92 \param[in] copyTop Whether to copy the current options.
94 void
95 IOFileTypeBase::pushOptions(bool copyTop)
97 if(copyTop == true)
99 _optStack.push(_optStack.top());
101 else
103 _optStack.push(OptionSet());
107 /*! Pops the next option set from the stack and makes it the current options.
109 void
110 IOFileTypeBase::popOptions(void)
112 if(_optStack.size() > 1)
114 _optStack.pop();
116 else
118 FWARNING(("IOFileTypeBase::popOptions: Can not remove last element "
119 "from options stack.\n"));
123 /*! Sets the option \a name to \a value in \a optSet overwriting
124 any previous value.
126 \param[in] optSet OptionSet to modify.
127 \param[in] name Name of the option.
128 \param[in] value Value of the option.
130 void
131 IOFileTypeBase::setOption(
132 OptionSet &optSet, const std::string &name, const std::string &value)
134 optSet[name] = IOOption(name, value);
137 /*! Removes the option \a name from \a optSet. If the option is not present
138 \c false is returned, \c true otherwise.
140 \param[in] optSet OptionSet to modify.
141 \param[in] name Name of the option.
142 \return Whether the option was successfully removed.
144 bool
145 IOFileTypeBase::unsetOption(OptionSet &optSet, const std::string &name)
147 bool retVal = false;
148 OptionSet::iterator oIt = optSet.find(name);
150 if(oIt != optSet.end())
152 optSet.erase(oIt);
153 retVal = true;
156 return retVal;
159 /*! Attempts to return the \a value associated with option \a name
160 in \a optSet. If the option is not present \c false is returned,
161 \c true otherwise and only in this case value is being set.
163 \param[in] optSet OptionSet to read.
164 \param[in] name Name of the option.
165 \param[out] value Value of option.
166 \return Whether the option is present.
168 bool
169 IOFileTypeBase::getOption(
170 const OptionSet &optSet, std::string const &name, std::string &value)
172 bool retVal = false;
173 OptionSet::const_iterator oIt = optSet.find(name);
175 if(oIt != optSet.end())
177 value = oIt->second.optValue;
178 retVal = true;
181 return retVal;
184 /*-------------------------------------------------------------------------*/
185 /* Constructors */
188 IOFileTypeBase::IOFileTypeBase(UInt32 const flags)
190 : _flags (flags),
191 _optStack( )
193 _optStack.push(OptionSet());
196 IOFileTypeBase::IOFileTypeBase(Self const &other)
198 : _flags (other._flags ),
199 _optStack(other._optStack)
203 /*-------------------------------------------------------------------------*/
204 /* Destructor */
206 IOFileTypeBase::~IOFileTypeBase(void)
208 // nothing to do
211 OSG_END_NAMESPACE