Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

67 rindas
2.2 KiB

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