4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Buffer public header */
26 #ifndef HH_SENF_Utils_Buffer_
27 #define HH_SENF_Utils_Buffer_ 1
30 #include <senf/config.hh>
32 //#include "Buffer.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
35 #if defined(SENF_BUFFER_USE_LOCALS)
37 # define SENF_SCOPED_BUFFER(type, sym, size) \
40 #elif defined(SENF_BUFFER_USE_ALLOCA)
43 # define SENF_SCOPED_BUFFER(type, sym, size) \
44 type * sym (static_cast<type *>(alloca(size*sizeof(type))));
46 #elif defined(SENF_BUFFER_USE_NEW)
48 # include <boost/scoped_array.hpp>
49 /** \brief Allocate a local buffer
51 SENF_SCOPED_BUFFER will allocate a local variable named \a sym as a buffer of \a size elements
52 of type \a type. The buffer will \e not be initialized in any way and \a type must be a POD
55 This macro is used when \a size is a dynamic expression and not a constant value. For constant
56 values, use \c boost::array (or C++ builtin arrays). Depending on compiler support, this version
57 will try to avoid dynamic memory allocation. The type of the declared local variable \a sym is
58 either pointer to \a type or array of \a type:
61 #include "../Utils/Buffer.hh"
63 void foo(std::string const & str)
65 // create temp copy of str (like c_str() member)
66 SENF_SCOPED_BUFFER(char, buf, str.size()+1);
67 *std::copy(str.begin(), str.end(), buf) = 0;
73 \param type Type of buffer element
74 \param sym Name of local symbol
75 \param size size of the Area to allocate.
79 # define SENF_SCOPED_BUFFER(type, sym, size) \
80 boost::scoped_array<type> _senf_scoped_buffer__ ## sym ## __ ## __LINE__ (new type[size]); \
81 type * sym (_senf_scoped_buffer__ ## sym ## __ ## __LINE__.get());
85 ///////////////////////////////hh.e////////////////////////////////////////
86 //#include "Buffer.cci"
87 //#include "Buffer.ct"
88 //#include "Buffer.cti"
95 // c-file-style: "senf"
96 // indent-tabs-mode: nil
97 // ispell-local-dictionary: "american"
98 // compile-command: "scons -u test"