What is the best practice/what do you guys do to organize various global definitions (such as static consts or typedefs)?
I'm working on a small sokoban library for fun, and the "problem" is that I've placed static members and typedefs in classes where it makes the most sense, but they are also required in other classes, so you get this awkward cross-referencing. Consider the following Level class:
namespace Sokoban {
// handles everything to do with a sokoban level
class Level
{
public:
static const std::string validTiles;
static const std::string validUndoData;
typedef Array2D<char> LevelArray_t;
/* --SNIP-- */
};
// in the .cpp file:
const std::string validTiles = "#@+$*. _pPbB";
const std::string validUndoData = "udlrUDLR";
/* --SNIP-- */
} // namespace Sokoban
This is all fine and good, but it turns out that Level is not the only class requiring access to validTiles, validUndoData and LevelArray_t. These are also required by the various level file parser classes and Collection class, so you get things like the following:
namespace Sokoban {
class CollectionParserSOK
{
public:
// parses a file and returns a collection containing all of the levels
Collection parse( const std::string& fileName ){
// cutting code here to get to the point, inBuf stores the current line read from the file
for( std::size_t i = 0; i != inBuf.size(); ++i )
{
if( Level::validTiles.find_first_of( inBuf[i] ) != std::string::npos ) // <------ Is "Level::validTiles" clean?
{
// do stuff
}
}
};
} // namespace Sokoban
Or this:
namespace Sokoban {
class Collection
{
public:
typedef Level::LevelArray_t::iterator LevelIterator_t;
};
} // namespace Sokoban
My gut is telling me that this could be done better, such as making a separate "Globals.hpp" header file and dumping definitions required in multiple classes (such as the above) in there.
Is that cleaner? Or am I making a big fuss over nothing?