X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FBuffer.hh;fp=senf%2FUtils%2FBuffer.hh;h=45100104b7690b880a79b5fd08a4fb57c7fe7942;hb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;hp=0000000000000000000000000000000000000000;hpb=164fe477094d42463722584e527a02379ab5d985;p=senf.git diff --git a/senf/Utils/Buffer.hh b/senf/Utils/Buffer.hh new file mode 100644 index 0000000..4510010 --- /dev/null +++ b/senf/Utils/Buffer.hh @@ -0,0 +1,100 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Buffer public header */ + +#ifndef HH_SENF_Utils_Buffer_ +#define HH_SENF_Utils_Buffer_ 1 + +// Custom includes +#include "../config.hh" + +//#include "Buffer.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +#if defined(SENF_BUFFER_USE_LOCALS) + +# define SENF_SCOPED_BUFFER(type, sym, size) \ + type sym[size]; + +#elif defined(SENF_BUFFER_USE_ALLOCA) + +# include +# define SENF_SCOPED_BUFFER(type, sym, size) \ + type * sym (static_cast(alloca(size*sizeof(type)))); + +#elif defined(SENF_BUFFER_USE_NEW) + +# include + /** \brief Allocate a local buffer + + SENF_SCOPED_BUFFER will allocate a local variable named \a sym as a buffer of \a size elements + of type \a type. The buffer will \e not be initialized in any way and \a type must be a POD + type. + + This macro is used when \a size is a dynamic expression and not a constant value. For constant + values, use \c boost::array (or C++ builtin arrays). Depending on compiler support, this version + will try to avoid dynamic memory allocation. The type of the declared local variable \a sym is + either pointer to \a type or array of \a type: + + \code + #include "../Utils/Buffer.hh" + + void foo(std::string const & str) + { + // create temp copy of str (like c_str() member) + SENF_SCOPED_BUFFER(char, buf, str.size()+1); + *std::copy(str.begin(), str.end(), buf) = 0; + + // use buf ... + } + \endcode + + \param type Type of buffer element + \param sym Name of local symbol + \param size size of the Area to allocate. + + \hideinitializer + */ +# define SENF_SCOPED_BUFFER(type, sym, size) \ + boost::scoped_array _senf_scoped_buffer__ ## sym ## __ ## __LINE__ (new type[size]); \ + type * sym (_senf_scoped_buffer__ ## sym ## __ ## __LINE__.get()); + +#endif + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "Buffer.cci" +//#include "Buffer.ct" +//#include "Buffer.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: