4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 */
31 //#include "Buffer.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
34 #if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA) && !defined(SENF_BUFFER_USE_NEW)
37 # if defined(__GNUC__)
38 # define SENF_BUFFER_USE_LOCALS 1
40 # // Add other compilers here ...
42 # // dynamic arrays are part of C99. Which is NOT part of C++
43 # // but lets try nonetheless ...
44 # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
45 # define SENF_BUFFER_USE_LOCALS 1
49 # if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA)
50 # define SENF_BUFFER_USE_NEW 1
55 #if defined(SENF_BUFFER_USE_LOCALS)
57 # define SENF_SCOPED_BUFFER(type, sym, size) \
60 #elif defined(SENF_BUFFER_USE_ALLOCA)
63 # define SENF_SCOPED_BUFFER(type, sym, size) \
64 type * sym (static_cast<type *>(alloca(size*sizeof(type))));
66 #elif defined(SENF_BUFFER_USE_NEW)
68 # include <boost/scoped_array.hpp>
69 /** \brief Allocate a local buffer
71 SENF_SCOPED_BUFFER will allocate a local variable named \a sym as a buffer of \a size elements
72 of type \a type. The buffer will \e not be initialized in any way and \a type must be a POD
75 This macro is used when \a size is a dynamic expression and not a constant value. For constant
76 values, use \c boost::aray (or C++ builtin arrays). Depending on compiler support, this version
77 will try to avoid dynamic memory allocation. The type of the declared local variable \a sym is
78 either pointer to \a type or array of \a type:
81 #include "Utils/Buffer.hh"
83 void foo(std::string const & str)
85 // create temp copy of str (like c_str() member)
86 SENF_SCOPED_BUFFER(char, buf, str.size()+1);
87 *std::copy(str.begin(), str.end(), buf) = 0;
93 \param type Type of buffer element
94 \param sym Name of local symbol
95 \param size size of the Area to allocate.
99 # define SENF_SCOPED_BUFFER(type, sym, size) \
100 boost::scoped_array<type> _senf_scoped_buffer__ ## sym ## __ ## __LINE__ (new type[size]); \
101 type * sym (_senf_scoped_buffer__ ## sym ## __ ## __LINE__.get());
105 ///////////////////////////////hh.e////////////////////////////////////////
106 //#include "Buffer.cci"
107 //#include "Buffer.ct"
108 //#include "Buffer.cti"
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"
119 // comment-column: 40