Skip to content

Commit

Permalink
Add and improve some debug operator<< functions
Browse files Browse the repository at this point in the history
Functioning debug operator insertion for RendererLight, LightSources and
Material (both actual objects and nullable pointers).
  • Loading branch information
Matthew Mott committed Sep 15, 2020
1 parent bd95bbf commit 7273d6d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
32 changes: 31 additions & 1 deletion include/irender.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ class RendererLight
};
typedef std::shared_ptr<RendererLight> RendererLightPtr;

/// Debug stream insertion for RendererLight
inline std::ostream& operator<< (std::ostream& os, const RendererLight& l)
{
return os << "RendererLight { worldOrigin = " << l.worldOrigin() << " }";
return os << "RendererLight(origin=" << l.worldOrigin() << ")";
}

/**
Expand Down Expand Up @@ -286,6 +287,35 @@ class LightSources
virtual void forEachLight(const RendererLightCallback& callback) const = 0;
};

/// Debug stream insertion for LightSources
inline std::ostream& operator<< (std::ostream& s, const LightSources& ls)
{
s << "LightSources(";

// Insert comma-separated list of RendererLights
bool addComma = false;
ls.forEachLight(
[&](const RendererLight& l)
{
if (addComma)
s << ", ";
s << l;
addComma = true;
}
);

return s << ")";
}

/// Debug stream insertion for possibly null LightSources pointer
inline std::ostream& operator<< (std::ostream& s, const LightSources* ls)
{
if (ls)
return s << *ls;
else
return s << "[no lightsources]";
}

/**
* \brief
* A list of lights which might (but don't necessarily) intersect a LitObject
Expand Down
24 changes: 16 additions & 8 deletions include/ishaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,26 @@ class Material

typedef std::shared_ptr<Material> MaterialPtr;

/**
* Stream insertion of Material for debugging purposes.
*/
/// Stream insertion of Material for debugging purposes.
inline
std::ostream& operator<< (std::ostream& os, const Material& shader) {
os << "Material { name = " << shader.getName()
<< ", filename = " << shader.getShaderFileName()
<< ", firstlayer = " << shader.firstLayer()
<< " }";
std::ostream& operator<< (std::ostream& os, const Material& shader)
{
os << "Material(name=" << shader.getName()
<< ", filename=" << shader.getShaderFileName()
<< ", firstlayer=" << shader.firstLayer()
<< ")";
return os;
}

/// Debug stream insertion of possibly null material pointer
inline std::ostream& operator<< (std::ostream& os, const Material* m)
{
if (m)
return os << *m;
else
return os << "[no material]";
}

typedef std::function<void(const std::string&)> ShaderNameCallback;

const char* const MODULE_SHADERSYSTEM = "MaterialManager";
Expand Down

0 comments on commit 7273d6d

Please sign in to comment.