00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00038 #include "blocxx/BLOCXX_config.h"
00039 #include "blocxx/DelayedFormat.hpp"
00040 #include "blocxx/StringStream.hpp"
00041 #include "blocxx/Assertion.hpp"
00042
00043 namespace BLOCXX_NAMESPACE
00044 {
00045 namespace DelayedFormatInternals
00046 {
00047 DelayedFormatReferenceBase::DelayedFormatReferenceBase()
00048 {
00049 }
00050 DelayedFormatReferenceBase::~DelayedFormatReferenceBase()
00051 {
00052 }
00053 std::ostream& DelayedFormatReferenceBase::dumpToStream(std::ostream& o) const
00054 {
00055 return doDumpToStream(o);
00056 }
00057 std::ostream& operator<<(std::ostream& o, const DelayedFormatReferenceBase& s)
00058 {
00059 return s.dumpToStream(o);
00060 }
00061 }
00062
00063 DelayedFormat::DelayedFormat(const String& format)
00064 : formatString(format), formatParameters()
00065 {
00066 }
00067
00068 DelayedFormat::operator String() const
00069 {
00070 return format().toString();
00071 }
00072
00073 Format DelayedFormat::format() const
00074 {
00075 return formatWithString(formatString.c_str());
00076 }
00077
00078 Format DelayedFormat::formatWithString(const String& fs) const
00079 {
00080 return formatWithString(fs.c_str());
00081 }
00082
00083 Format DelayedFormat::formatWithString(const char* fsp) const
00084 {
00085
00086 BLOCXX_ASSERT( formatParameters.size() <= 9 );
00087 const Array<Reference<DelayedFormatInternals::DelayedFormatReferenceBase> >& fp = formatParameters;
00088 switch( formatParameters.size() )
00089 {
00090 case 0:
00091 return Format(fsp, "");
00092 case 1:
00093 return Format(fsp, *fp[0]);
00094 case 2:
00095 return Format(fsp, *fp[0], *fp[1]);
00096 case 3:
00097 return Format(fsp, *fp[0], *fp[1], *fp[2]);
00098 case 4:
00099 return Format(fsp, *fp[0], *fp[1], *fp[2], *fp[3]);
00100 case 5:
00101 return Format(fsp, *fp[0], *fp[1], *fp[2], *fp[3], *fp[4]);
00102 case 6:
00103 return Format(fsp, *fp[0], *fp[1], *fp[2], *fp[3], *fp[4], *fp[5]);
00104 case 7:
00105 return Format(fsp, *fp[0], *fp[1], *fp[2], *fp[3], *fp[4], *fp[5], *fp[6]);
00106 case 8:
00107 return Format(fsp, *fp[0], *fp[1], *fp[2], *fp[3], *fp[4], *fp[5], *fp[6], *fp[7]);
00108 case 9:
00109 return Format(fsp, *fp[0], *fp[1], *fp[2], *fp[3], *fp[4], *fp[5], *fp[6], *fp[7], *fp[8]);
00110 }
00111
00112 return Format("","");
00113 }
00114
00115
00116 }