core/vul/vul_sprintf.h
Go to the documentation of this file.
00001 // This is core/vul/vul_sprintf.h
00002 #ifndef vul_sprintf_h_
00003 #define vul_sprintf_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief creates a formatted ANSI C++ string
00010 // \author Andrew W. Fitzgibbon, Oxford RRG
00011 // \date   08 Aug 96
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   10 June 1999 fsm removed constructor from 'const vcl_string &' and
00016 //                    changed remaining constructors to use do_vul_sprintf().
00017 //   Peter Vanroose   27/05/2001: Corrected the documentation
00018 // \endverbatim
00019 //-----------------------------------------------------------------------------
00020 
00021 #include <vcl_string.h>
00022 #include <vcl_iosfwd.h>
00023 
00024 //: C++ conforming replacement to the ANSI C functions sprintf and printf.
00025 // vul_sprintf works in the same way as sprintf but is itself an ANSI C++ string
00026 // which can either be kept or output directly using streams  e.g.
00027 // \code
00028 // vcl_cerr << vul_sprintf("int %d, float %f ", 1, 3.14)
00029 //          << bigobject << vcl_endl;
00030 // \endcode
00031 
00032 struct vul_sprintf : public vcl_string
00033 {
00034   // ISO C++ does not allow reference types or structure types for the
00035   // argument preceding ... in a function taking a variable number of
00036   // parameters.
00037   // So we can't have any of these constructors:
00038   //   vul_sprintf(vcl_string const& fmt, ...);
00039   //   vul_sprintf(vcl_string fmt, ...);
00040   vul_sprintf(char const *fmt, ...);
00041 
00042 #ifndef VCL_WIN32
00043   // assignment
00044   vul_sprintf& operator=(vcl_string const& s)
00045   { vcl_string::operator=(s); return *this; }
00046   vul_sprintf& operator=(char const* s)
00047   { vcl_string::operator=(s); return *this; }
00048 #endif
00049 
00050   operator char const* () const { return c_str(); }
00051 };
00052 
00053 vcl_ostream& operator<<(vcl_ostream &os, const vul_sprintf& s);
00054 
00055 #endif // vul_sprintf_h_