"Fossies" - the Fresh Open Source Software Archive

Member "encfs-1.9.5/encfs/autosprintf.h" (27 Apr 2018, 2208 Bytes) of package /linux/misc/encfs-1.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "autosprintf.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.9.4_vs_1.9.5.

    1 /* Class autosprintf - formatted output to an ostream.
    2    Copyright (C) 2002 Free Software Foundation, Inc.
    3 
    4    This program is free software: you can redistribute it and/or modify
    5    it under the terms of the GNU Library General Public License as published by
    6    the Free Software Foundation, either version 2 of the License, or
    7    (at your option) any later version.
    8 
    9    This program is distributed in the hope that it will be useful,
   10    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12    GNU Library General Public License for more details.
   13 
   14    You should have received a copy of the GNU Library General Public License
   15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
   16 
   17 #ifndef _AUTOSPRINTF_H
   18 #define _AUTOSPRINTF_H
   19 
   20 #ifndef __attribute__
   21 /* This feature is available in gcc versions 2.5 and later.  */
   22 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
   23 #define __attribute__(Spec) /* empty */
   24 #endif
   25 /* The __-protected variants of `format' and `printf' attributes
   26    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
   27 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
   28 #define __format__ format
   29 #define __printf__ printf
   30 #endif
   31 #endif
   32 
   33 #include <iostream>
   34 #include <string>
   35 
   36 namespace gnu {
   37 /* A temporary object, usually allocated on the stack, representing
   38    the result of an asprintf() call.  */
   39 class autosprintf {
   40  public:
   41   /* Constructor: takes a format string and the printf arguments.  */
   42   autosprintf(const char* format, ...)
   43       __attribute__((__format__(__printf__, 2, 3)));
   44   /* Copy constructor.  */
   45   autosprintf(const autosprintf& src);
   46   /* Destructor: frees the temporarily allocated string.  */
   47   ~autosprintf();
   48   /* Conversion to string.  */
   49   explicit operator char*() const;
   50   explicit operator std::string() const;
   51   /* Output to an ostream.  */
   52   friend inline std::ostream& operator<<(std::ostream& stream,
   53                                          const autosprintf& tmp) {
   54     stream << (tmp.str ? tmp.str : "(error in autosprintf)");
   55     return stream;
   56   }
   57 
   58  private:
   59   char* str;
   60 };
   61 }
   62 
   63 #endif /* _AUTOSPRINTF_H */