Skip to content

Commit 5237c3e

Browse files
authored
Merge pull request #5262 from johnhaddon/moreFormat
More `boost::format` to `fmt::format` conversions
2 parents 25f11e4 + 4594428 commit 5237c3e

File tree

18 files changed

+124
-101
lines changed

18 files changed

+124
-101
lines changed

src/GafferImageModule/CoreBinding.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
#include "IECorePython/SimpleTypedDataBinding.h"
5757

58+
#include "fmt/format.h"
59+
5860
using namespace boost::python;
5961
using namespace Gaffer;
6062
using namespace GafferImage;
@@ -240,21 +242,17 @@ std::string formatRepr( const GafferImage::Format &format )
240242
else if ( format.getDisplayWindow().min == Imath::V2i( 0 ) )
241243
{
242244
Imath::Box2i box( format.getDisplayWindow() );
243-
return std::string(
244-
boost::str( boost::format(
245-
"GafferImage.Format( %d, %d, %.3f )" )
246-
% box.max.x % box.max.y % format.getPixelAspect()
247-
)
245+
return fmt::format(
246+
"GafferImage.Format( {}, {}, {:.3f} )",
247+
box.max.x, box.max.y, format.getPixelAspect()
248248
);
249249
}
250250
else
251251
{
252252
Imath::Box2i box( format.getDisplayWindow() );
253-
return std::string(
254-
boost::str( boost::format(
255-
"GafferImage.Format( imath.Box2i( imath.V2i( %d, %d ), imath.V2i( %d, %d ) ), %.3f )" )
256-
% box.min.x % box.min.y % box.max.x % box.max.y % format.getPixelAspect()
257-
)
253+
return fmt::format(
254+
"GafferImage.Format( imath.Box2i( imath.V2i( {}, {} ), imath.V2i( {}, {} ) ), {:.3f} )",
255+
box.min.x, box.min.y, box.max.x, box.max.y, format.getPixelAspect()
258256
);
259257
}
260258
}

src/GafferImageTest/ContextSanitiser.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
#include "IECore/MessageHandler.h"
4545

46+
#include "fmt/format.h"
47+
4648
using namespace IECore;
4749
using namespace Gaffer;
4850
using namespace GafferImage;
@@ -99,22 +101,22 @@ void ContextSanitiser::warn( const Gaffer::Process &process, const IECore::Inter
99101

100102
if( m_warningsEmitted.insert( warning ).second )
101103
{
102-
std::string message = boost::str(
103-
boost::format( "%s in context for %s %s" )
104-
% contextVariable.string()
105-
% process.plug()->relativeName(
106-
process.plug()->ancestor<ScriptNode>()
107-
)
108-
% process.type()
104+
std::string message = fmt::format(
105+
"{} in context for {} {}",
106+
contextVariable.string(),
107+
process.plug()->relativeName(
108+
process.plug()->ancestor<ScriptNode>()
109+
),
110+
process.type().string()
109111
);
110112
if( process.parent() )
111113
{
112-
message += boost::str(
113-
boost::format( " (called from %s %s)" )
114-
% process.parent()->plug()->relativeName(
115-
process.parent()->plug()->ancestor<ScriptNode>()
116-
)
117-
% process.parent()->type()
114+
message += fmt::format(
115+
" (called from {} {})",
116+
process.parent()->plug()->relativeName(
117+
process.parent()->plug()->ancestor<ScriptNode>()
118+
),
119+
process.parent()->type().string()
118120
);
119121
}
120122
IECore::msg(

src/GafferModule/AnimationBinding.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#include "Gaffer/Animation.h"
4646

47+
#include "fmt/format.h"
48+
4749
#include "boost/lexical_cast.hpp"
4850

4951
#include <cmath>
@@ -128,7 +130,7 @@ void setPosition( Animation::Tangent &t, const Imath::V2d& position, const bool
128130

129131
std::string slopeRepr( const double slope )
130132
{
131-
return boost::str( boost::format( ( ( std::isinf( slope ) ) ? "float( '%.9g' )" : "%.9g" ) ) % slope );
133+
return fmt::format( std::isinf( slope ) ? "float( '{:.9g}' )" : "{:.9g}", slope );
132134
}
133135

134136
void setTieMode( Animation::Key &k, const Animation::TieMode mode )
@@ -139,16 +141,16 @@ void setTieMode( Animation::Key &k, const Animation::TieMode mode )
139141

140142
std::string keyRepr( const Animation::Key &k )
141143
{
142-
return boost::str( boost::format(
143-
"Gaffer.Animation.Key( %.9g, %.9g, Gaffer.Animation.Interpolation.%s, %s, %.9g, %s, %.9g, Gaffer.Animation.TieMode.%s )" )
144-
% k.getTime()
145-
% k.getValue()
146-
% Animation::toString( k.getInterpolation() )
147-
% slopeRepr( k.tangentIn().getSlope() )
148-
% k.tangentIn().getScale()
149-
% slopeRepr( k.tangentOut().getSlope() )
150-
% k.tangentOut().getScale()
151-
% Animation::toString( k.getTieMode() )
144+
return fmt::format(
145+
"Gaffer.Animation.Key( {:.9g}, {:.9g}, Gaffer.Animation.Interpolation.{}, {}, {:.9g}, {}, {:.9g}, Gaffer.Animation.TieMode.{} )",
146+
k.getTime(),
147+
k.getValue(),
148+
Animation::toString( k.getInterpolation() ),
149+
slopeRepr( k.tangentIn().getSlope() ),
150+
k.tangentIn().getScale(),
151+
slopeRepr( k.tangentOut().getSlope() ),
152+
k.tangentOut().getScale(),
153+
Animation::toString( k.getTieMode() )
152154
);
153155
};
154156

src/GafferModule/ScriptNodeBinding.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
#include "boost/lexical_cast.hpp"
6363
#include "boost/regex.hpp"
6464

65+
#include "fmt/format.h"
66+
6567
#include <memory>
6668

6769
using namespace boost;
@@ -116,11 +118,9 @@ namespace
116118

117119
const std::string formattedErrorContext( int lineNumber, const std::string &context )
118120
{
119-
return boost::str(
120-
boost::format( "Line %d%s%s" ) %
121-
lineNumber %
122-
(!context.empty() ? " of " : "") %
123-
context
121+
return fmt::format( "Line {}{}{}",
122+
lineNumber, !context.empty() ? " of " : "",
123+
context
124124
);
125125
}
126126

src/GafferModule/Transform2DPlugBinding.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#include "Gaffer/Transform2DPlug.h"
4444

45+
#include "fmt/format.h"
46+
4547
using namespace boost::python;
4648
using namespace Imath;
4749
using namespace GafferBindings;
@@ -78,10 +80,9 @@ class Transform2DPlugSerialiser : public ValuePlugSerialiser
7880

7981
auto appendDefault = [&result]( const V2f &d, const V2f &defaultD, const char *name )
8082
{
81-
static boost::format formatter( "%1% = imath.V2f( %2%, %3% ), " );
8283
if( d != defaultD )
8384
{
84-
result += boost::str( formatter % name % d.x % d.y );
85+
result += fmt::format( "{} = imath.V2f( {}, {} ), ", name, d.x, d.y );
8586
}
8687
};
8788
appendDefault( plug->translatePlug()->defaultValue(), V2f( 0 ), "defaultTranslate" );

src/GafferModule/TransformPlugBinding.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
#include "Gaffer/TransformPlug.h"
4545

46+
#include "fmt/format.h"
47+
4648
using namespace boost::python;
4749
using namespace Imath;
4850
using namespace GafferBindings;
@@ -78,10 +80,9 @@ class TransformPlugSerialiser : public ValuePlugSerialiser
7880

7981
auto appendDefault = [&result]( const V3f &d, const V3f &defaultD, const char *name )
8082
{
81-
static boost::format formatter( "%1% = imath.V3f( %2%, %3%, %4% ), " );
8283
if( d != defaultD )
8384
{
84-
result += boost::str( formatter % name % d.x % d.y % d.z );
85+
result += fmt::format( "{} = imath.V3f( {}, {}, {} ), ", name, d.x, d.y, d.z );
8586
}
8687
};
8788
appendDefault( plug->translatePlug()->defaultValue(), V3f( 0 ), "defaultTranslate" );

src/GafferScene/IECoreGLPreview/Renderer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@
7878
#endif
7979

8080
#include "boost/algorithm/string/predicate.hpp"
81-
#include "boost/format.hpp"
8281

8382
#include "tbb/concurrent_queue.h"
8483

84+
#include "fmt/format.h"
85+
8586
#include <functional>
8687
#include <unordered_map>
8788
#include <vector>
@@ -185,7 +186,7 @@ T *reportedCast( const IECore::RunTimeTyped *v, const char *type, const IECore::
185186
return t;
186187
}
187188

188-
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer", boost::format( "Expected %s but got %s for %s \"%s\"." ) % T::staticTypeName() % v->typeName() % type % name.c_str() );
189+
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer", fmt::format( "Expected {} but got {} for {} \"{}\".", T::staticTypeName(), v->typeName(), type, name.string() ) );
189190
return nullptr;
190191
}
191192

@@ -893,7 +894,7 @@ class OpenGLRenderer final : public IECoreScenePreview::Renderer
893894
}
894895
else
895896
{
896-
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer::option", boost::format( "Unknown option \"%s\"." ) % name.c_str() );
897+
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer::option", fmt::format( "Unknown option \"{}\".", name.string() ) );
897898
}
898899
}
899900

@@ -1015,7 +1016,7 @@ class OpenGLRenderer final : public IECoreScenePreview::Renderer
10151016
}
10161017
else if( boost::starts_with( name.string(), "gl:" ) || name.string().find( ":" ) == string::npos )
10171018
{
1018-
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer::command", boost::format( "Unknown command \"%s\"." ) % name.c_str() );
1019+
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer::command", fmt::format( "Unknown command \"{}\".", name.string() ) );
10191020
}
10201021

10211022
return nullptr;
@@ -1227,15 +1228,15 @@ class OpenGLRenderer final : public IECoreScenePreview::Renderer
12271228
}
12281229
else
12291230
{
1230-
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer", boost::format( "Unsupported data format \"%s\"." ) % data );
1231+
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer", fmt::format( "Unsupported data format \"{}\".", data ) );
12311232
return;
12321233
}
12331234

12341235
const string &type = namedOutput.second->getType();
12351236
IECore::WriterPtr writer = IECore::Writer::create( image, "tmp." + type );
12361237
if( !writer )
12371238
{
1238-
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer", boost::format( "Unsupported display type \"%s\"." ) % type );
1239+
IECore::msg( IECore::Msg::Warning, "IECoreGL::Renderer", fmt::format( "Unsupported display type \"{}\".", type ) );
12391240
return;
12401241
}
12411242

src/GafferScene/IECoreScenePreview/CapturingRenderer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "IECore/MessageHandler.h"
4040
#include "IECore/SimpleTypedData.h"
4141

42+
#include "fmt/format.h"
43+
4244
using namespace std;
4345
using namespace IECore;
4446
using namespace IECoreScenePreview;
@@ -145,7 +147,7 @@ Renderer::ObjectInterfacePtr CapturingRenderer::object( const std::string &name,
145147
if( !m_capturedObjects.insert( a, name ) )
146148
{
147149
IECore::msg( IECore::Msg::Warning, "CapturingRenderer::object",
148-
boost::str( boost::format( "Object named \"%s\" already exists" ) % name )
150+
fmt::format( "Object named \"{}\" already exists", name )
149151
);
150152
return nullptr;
151153
}

src/GafferSceneModule/PrimitivesBinding.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
#include "GafferBindings/DependencyNodeBinding.h"
5959

60+
#include "fmt/format.h"
61+
6062
using namespace std;
6163
using namespace boost::python;
6264
using namespace IECorePython;
@@ -105,7 +107,7 @@ class LightSerialiser : public GafferBindings::NodeSerialiser
105107
const std::string shaderName = shaderNamePlug ? shaderNamePlug->getValue() : "";
106108
if( shaderName.size() )
107109
{
108-
return defaultPC + boost::str( boost::format( "%s.loadShader( \"%s\" )\n" ) % identifier % shaderName );
110+
return defaultPC + fmt::format( "{}.loadShader( \"{}\" )\n", identifier, shaderName );
109111
}
110112

111113
return defaultPC;
@@ -129,7 +131,7 @@ class LightFilterSerialiser : public GafferBindings::NodeSerialiser
129131

130132
if( shaderName.size() )
131133
{
132-
return defaultPostConstructor + boost::str( boost::format( "%s.loadShader( \"%s\" )\n" ) % identifier % shaderName );
134+
return defaultPostConstructor + fmt::format( "{}.loadShader( \"{}\" )\n", identifier, shaderName );
133135
}
134136

135137
return defaultPostConstructor;

src/GafferSceneModule/ShaderBinding.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#include "Gaffer/StringPlug.h"
4949

50+
#include "fmt/format.h"
51+
5052
using namespace boost::python;
5153

5254
using namespace Gaffer;
@@ -110,7 +112,7 @@ class ShaderSerialiser : public GafferBindings::NodeSerialiser
110112
const std::string shaderName = shader->namePlug()->getValue();
111113
if( shaderName.size() )
112114
{
113-
return defaultPC + boost::str( boost::format( "%s.loadShader( \"%s\" )\n" ) % identifier % shaderName );
115+
return defaultPC + fmt::format( "{}.loadShader( \"{}\" )\n", identifier, shaderName );
114116
}
115117

116118
return defaultPC;

0 commit comments

Comments
 (0)