2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief Buffer public header */
29 //#include "Buffer.mpp"
30 ///////////////////////////////hh.p////////////////////////////////////////
32 #if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA) && !defined(SENF_BUFFER_USE_NEW)
35 # if defined(__GNUC__)
36 # define SENF_BUFFER_USE_LOCALS 1
38 # // Add other compilers here ...
40 # // dynamic arrays are part of C99. Which is NOT part of C++
41 # // but lets try nonetheless ...
42 # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
43 # define SENF_BUFFER_USE_LOCALS 1
47 # if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA)
48 # define SENF_BUFFER_USE_NEW 1
53 #if defined(SENF_BUFFER_USE_LOCALS)
55 # define SENF_SCOPED_BUFFER(type, sym, size) \
58 #elif defined(SENF_BUFFER_USE_ALLOCA)
61 # define SENF_SCOPED_BUFFER(type, sym, size) \
62 type * sym (static_cast<type *>(alloca(size*sizeof(type))));
64 #elif defined(SENF_BUFFER_USE_NEW)
66 # include <boost/scoped_array.hpp>
67 /** \brief Allocate a local buffer
69 SENF_SCOPED_BUFFER will allocate a local variable named \a sym as a buffer of \a size elements
70 of type \a type. The buffer will \e not be initialized in any way and \a type must be a POD
73 This macro is used when \a size is a dynamic expression and not a constant value. For constant
74 values, use \c boost::aray (or C++ builtin arrays). Depending on compiler support, this version
75 will try to avoid dynamic memory allocation. The type of the declared local variable \a sym is
76 either pointer to \a type or array of \a type:
79 #include "Utils/Buffer.hh"
81 void foo(std::string const & str)
83 // create temp copy of str (like c_str() member)
84 SENF_SCOPED_BUFFER(char, buf, str.size()+1);
85 *std::copy(str.begin(), str.end(), buf) = 0;
91 \param type Type of buffer element
92 \param sym Name of local symbol
93 \param size size of the Area to allocate.
97 # define SENF_SCOPED_BUFFER(type, sym, size) \
98 boost::scoped_array<type> _senf_scoped_buffer__ ## sym ## __ ## __LINE__ (new type[size]); \
99 type * sym (_senf_scoped_buffer__ ## sym ## __ ## __LINE__.get());
103 ///////////////////////////////hh.e////////////////////////////////////////
104 //#include "Buffer.cci"
105 //#include "Buffer.ct"
106 //#include "Buffer.cti"
113 // c-file-style: "senf"
114 // indent-tabs-mode: nil
115 // ispell-local-dictionary: "american"