4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Buffer public header */
31 #ifndef HH_SENF_Utils_Buffer_
32 #define HH_SENF_Utils_Buffer_ 1
35 #include <senf/config.hh>
37 //#include "Buffer.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 #if defined(SENF_BUFFER_USE_LOCALS)
42 # define SENF_SCOPED_BUFFER(type, sym, size) \
45 #elif defined(SENF_BUFFER_USE_ALLOCA)
48 # define SENF_SCOPED_BUFFER(type, sym, size) \
49 type * sym (static_cast<type *>(alloca(size*sizeof(type))));
51 #elif defined(SENF_BUFFER_USE_NEW)
53 # include <boost/scoped_array.hpp>
54 /** \brief Allocate a local buffer
56 SENF_SCOPED_BUFFER will allocate a local variable named \a sym as a buffer of \a size elements
57 of type \a type. The buffer will \e not be initialized in any way and \a type must be a POD
60 This macro is used when \a size is a dynamic expression and not a constant value. For constant
61 values, use \c boost::array (or C++ builtin arrays). Depending on compiler support, this version
62 will try to avoid dynamic memory allocation. The type of the declared local variable \a sym is
63 either pointer to \a type or array of \a type:
66 #include "../Utils/Buffer.hh"
68 void foo(std::string const & str)
70 // create temp copy of str (like c_str() member)
71 SENF_SCOPED_BUFFER(char, buf, str.size()+1);
72 *std::copy(str.begin(), str.end(), buf) = 0;
78 \param type Type of buffer element
79 \param sym Name of local symbol
80 \param size size of the Area to allocate.
84 # define SENF_SCOPED_BUFFER(type, sym, size) \
85 boost::scoped_array<type> _senf_scoped_buffer__ ## sym ## __ ## __LINE__ (new type[size]); \
86 type * sym (_senf_scoped_buffer__ ## sym ## __ ## __LINE__.get());
90 //-/////////////////////////////////////////////////////////////////////////////////////////////////
91 //#include "Buffer.cci"
92 //#include "Buffer.ct"
93 //#include "Buffer.cti"
100 // c-file-style: "senf"
101 // indent-tabs-mode: nil
102 // ispell-local-dictionary: "american"
103 // compile-command: "scons -u test"
104 // comment-column: 40