|
||||
File indexing completed on 2025-01-17 09:55:08
0001 /* Class autosprintf - formatted output to an ostream. 0002 Copyright (C) 2002, 2012-2016 Free Software Foundation, Inc. 0003 0004 This program is free software: you can redistribute it and/or modify 0005 it under the terms of the GNU Lesser General Public License as published by 0006 the Free Software Foundation; either version 2.1 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU Lesser General Public License for more details. 0013 0014 You should have received a copy of the GNU Lesser General Public License 0015 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 0016 0017 #ifndef _AUTOSPRINTF_H 0018 #define _AUTOSPRINTF_H 0019 0020 /* This feature is available in gcc versions 2.5 and later. */ 0021 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ 0022 # define _AUTOSPRINTF_ATTRIBUTE_FORMAT() /* empty */ 0023 #else 0024 /* The __-protected variants of 'format' and 'printf' attributes 0025 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 0026 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 0027 # define _AUTOSPRINTF_ATTRIBUTE_FORMAT() \ 0028 __attribute__ ((__format__ (__printf__, 2, 3))) 0029 # else 0030 # define _AUTOSPRINTF_ATTRIBUTE_FORMAT() \ 0031 __attribute__ ((format (printf, 2, 3))) 0032 # endif 0033 #endif 0034 0035 #include <string> 0036 #include <iostream> 0037 0038 namespace gnu 0039 { 0040 /* A temporary object, usually allocated on the stack, representing 0041 the result of an asprintf() call. */ 0042 class autosprintf 0043 { 0044 public: 0045 /* Constructor: takes a format string and the printf arguments. */ 0046 autosprintf (const char *format, ...) 0047 _AUTOSPRINTF_ATTRIBUTE_FORMAT(); 0048 /* Copy constructor. */ 0049 autosprintf (const autosprintf& src); 0050 /* Assignment operator. */ 0051 autosprintf& operator = (autosprintf temporary); 0052 /* Destructor: frees the temporarily allocated string. */ 0053 ~autosprintf (); 0054 /* Conversion to string. */ 0055 operator char * () const; 0056 operator std::string () const; 0057 /* Output to an ostream. */ 0058 friend inline std::ostream& operator<< (std::ostream& stream, const autosprintf& tmp) 0059 { 0060 stream << (tmp.str ? tmp.str : "(error in autosprintf)"); 0061 return stream; 0062 } 0063 private: 0064 char *str; 0065 }; 0066 } 0067 0068 #endif /* _AUTOSPRINTF_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |