C++11: Use unordered containers from std instead of boost

This commit is contained in:
Marius Kintel 2016-01-10 17:19:43 -05:00
parent 34e7761a79
commit a9d2cb2838
25 changed files with 113 additions and 86 deletions

View file

@ -277,6 +277,7 @@ HEADERS += src/typedefs.h \
src/function.h \
src/exceptions.h \
src/grid.h \
src/hash.h \
src/highlighter.h \
src/localscope.h \
src/module.h \
@ -415,6 +416,7 @@ SOURCES += src/version_check.cc \
src/AutoUpdater.cc \
\
src/grid.cc \
src/hash.cc \
src/builtin.cc \
src/calc.cc \
src/export.cc \

View file

@ -2,12 +2,12 @@
#include "tesselator.h"
#include "printutils.h"
#include "Reindexer.h"
#include "grid.h"
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/functional/hash.hpp>
static void *stdAlloc(void* userData, unsigned int size) {
TESS_NOTUSED(userData);
return malloc(size);
@ -27,7 +27,7 @@ typedef std::pair<int,int> IndexedEdge;
class EdgeDict {
public:
// Counts occurrences of edges
typedef boost::unordered_map<IndexedEdge, int> IndexedEdgeDict;
typedef std::unordered_map<IndexedEdge, int, boost::hash<IndexedEdge>> IndexedEdgeDict;
EdgeDict() { }
@ -148,7 +148,7 @@ public:
}
while (!v2e.empty()) {
boost::unordered_map<int, std::list<int> >::iterator it;
std::unordered_map<int, std::list<int> >::iterator it;
for (it = v2e.begin();it != v2e.end();it++) {
if (it->second.size() == 1) { // First single vertex
int vidx = it->first;
@ -167,8 +167,8 @@ public:
}
IndexedEdgeDict edges;
boost::unordered_map<int, std::list<int> > v2e;
boost::unordered_map<int, std::list<int> > v2e_reverse;
std::unordered_map<int, std::list<int> > v2e;
std::unordered_map<int, std::list<int> > v2e_reverse;
};

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <boost/unordered_map.hpp>
#include <unordered_map>
/*!
Caches FileModules based on their filenames
@ -26,5 +26,5 @@ private:
class FileModule *module;
std::string cache_id;
};
boost::unordered_map<std::string, cache_entry> entries;
std::unordered_map<std::string, cache_entry> entries;
};

View file

@ -1,9 +1,10 @@
#pragma once
#include <boost/unordered_map.hpp>
#include <boost/functional.hpp>
#include <unordered_map>
#include <functional>
#include <vector>
#include <algorithm>
#include "hash.h"
/*!
Reindexes a collection of elements of type T.
@ -20,7 +21,7 @@ public:
Looks up a value. Will insert the value if it doesn't already exist.
Returns the new index. */
int lookup(const T &val) {
typename boost::unordered_map<T, int>::const_iterator iter = this->map.find(val);
typename std::unordered_map<T, int>::const_iterator iter = this->map.find(val);
if (iter != this->map.end()) return iter->second;
else {
this->map.insert(std::make_pair(val, this->map.size()));
@ -40,7 +41,7 @@ public:
*/
const T *getArray() {
this->vec.resize(this->map.size());
typename boost::unordered_map<T, int>::const_iterator iter = this->map.begin();
typename std::unordered_map<T, int>::const_iterator iter = this->map.begin();
while (iter != this->map.end()) {
this->vec[iter->second] = iter->first;
iter++;
@ -57,6 +58,6 @@ public:
}
private:
boost::unordered_map<T, int> map;
std::unordered_map<T, int> map;
std::vector<T> vec;
};

View file

@ -31,7 +31,8 @@
#include "system-gl.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <boost/functional/hash.hpp>
ThrownTogetherRenderer::ThrownTogetherRenderer(CSGChain *root_chain,
CSGChain *highlights_chain,
@ -65,7 +66,9 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
{
PRINTD("Thrown renderCSGChain");
glDepthFunc(GL_LEQUAL);
boost::unordered_map<std::pair<const Geometry*,const Transform3d*>,int> geomVisitMark;
std::unordered_map<std::pair<const Geometry*,const Transform3d*>,
int,
boost::hash<std::pair<const Geometry*,const Transform3d*>>> geomVisitMark;
for(const auto &obj : chain->objects) {
if (geomVisitMark[std::make_pair(obj.geom.get(), &obj.matrix)]++ > 0)
continue;

View file

@ -1,15 +1,15 @@
#pragma once
#include <string>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include "module.h"
#include "localscope.h"
class Builtins
{
public:
typedef boost::unordered_map<std::string, class AbstractFunction*> FunctionContainer;
typedef boost::unordered_map<std::string, class AbstractModule*> ModuleContainer;
typedef std::unordered_map<std::string, class AbstractFunction*> FunctionContainer;
typedef std::unordered_map<std::string, class AbstractModule*> ModuleContainer;
static Builtins *instance(bool erase = false);
static void init(const char *name, class AbstractModule *module);
@ -25,5 +25,5 @@ private:
LocalScope globalscope;
boost::unordered_map<std::string, std::string> deprecations;
std::unordered_map<std::string, std::string> deprecations;
};

View file

@ -44,7 +44,7 @@
#pragma once
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <boost/format.hpp>
#include "printutils.h"
@ -57,11 +57,11 @@ class Cache
: keyPtr(0), t(data), c(cost), p(0), n(0) {}
const Key *keyPtr; T *t; int c; Node *p,*n;
};
typedef typename boost::unordered_map<Key, Node> map_type;
typedef typename std::unordered_map<Key, Node> map_type;
typedef typename map_type::iterator iterator_type;
typedef typename map_type::value_type value_type;
boost::unordered_map<Key, Node> hash;
std::unordered_map<Key, Node> hash;
Node *f, *l;
void *unused;
int mx, total;

View file

@ -32,7 +32,7 @@
#include <map>
#include <queue>
#include <boost/unordered_set.hpp>
#include <unordered_set>
namespace CGALUtils {
@ -46,7 +46,7 @@ namespace CGALUtils {
}
}
// Also make sure that there is only one shell:
boost::unordered_set<typename Polyhedron::Facet_const_handle, typename CGAL::Handle_hash_function> visited;
std::unordered_set<typename Polyhedron::Facet_const_handle, typename CGAL::Handle_hash_function> visited;
// c++11
// visited.reserve(p.size_of_facets());

View file

@ -27,13 +27,10 @@
#endif
#include "svg.h"
#include "Reindexer.h"
#include "GeometryUtils.h"
#include <map>
#include <queue>
#include <boost/unordered_set.hpp>
static void add_outline_to_poly(CGAL_Nef_polyhedron2::Explorer &explorer,
CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator circ,

View file

@ -28,11 +28,11 @@
#include "svg.h"
#include "Reindexer.h"
#include "hash.h"
#include "GeometryUtils.h"
#include <map>
#include <queue>
#include <boost/unordered_set.hpp>
static CGAL_Nef_polyhedron *createNefPolyhedronFromPolySet(const PolySet &ps)
{

View file

@ -31,7 +31,7 @@
#include "printutils.h"
#include <sstream>
#include <assert.h>
#include <boost/unordered/unordered_map.hpp>
#include <unordered_map>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/assign/list_of.hpp>
@ -45,7 +45,7 @@ public:
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const;
private:
boost::unordered_map<std::string, Color4f> webcolors;
std::unordered_map<std::string, Color4f> webcolors;
};
ColorModule::ColorModule()
@ -204,7 +204,7 @@ ColorModule::ColorModule()
// additional OpenSCAD specific entry
("transparent", Color4f(0, 0, 0, 0))
.convert_to_container<boost::unordered_map<std::string, Color4f> >();
.convert_to_container<std::unordered_map<std::string, Color4f> >();
}
ColorModule::~ColorModule()

View file

@ -2,7 +2,7 @@
#include <string>
#include <vector>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include "value.h"
#include "typedefs.h"
#include "memory.h"
@ -40,7 +40,7 @@ protected:
const Context *parent;
Stack *ctx_stack;
typedef boost::unordered_map<std::string, ValuePtr> ValueMap;
typedef std::unordered_map<std::string, ValuePtr> ValueMap;
ValueMap constants;
ValueMap variables;
ValueMap config_variables;

View file

@ -33,7 +33,7 @@
#include <fstream>
#include "mathc99.h"
#include <assert.h>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <algorithm>
@ -86,7 +86,7 @@ DxfData::DxfData(double fn, double fs, double fa,
Grid2d< std::vector<int> > grid(GRID_COARSE);
std::vector<Line> lines; // Global lines
boost::unordered_map< std::string, std::vector<Line> > blockdata; // Lines in blocks
std::unordered_map< std::string, std::vector<Line> > blockdata; // Lines in blocks
bool in_entities_section = false;
bool in_blocks_section = false;
@ -124,7 +124,7 @@ DxfData::DxfData(double fn, double fs, double fa,
for (int j = 0; j < 2; j++)
coords[i][j] = 0;
typedef boost::unordered_map<std::string, int> EntityList;
typedef std::unordered_map<std::string, int> EntityList;
EntityList unsupported_entities_list;
//

View file

@ -39,8 +39,8 @@
#include <stdint.h>
#include <boost/filesystem.hpp>
boost::unordered_map<std::string, ValuePtr> dxf_dim_cache;
boost::unordered_map<std::string, ValuePtr> dxf_cross_cache;
std::unordered_map<std::string, ValuePtr> dxf_dim_cache;
std::unordered_map<std::string, ValuePtr> dxf_cross_cache;
namespace fs = boost::filesystem;
ValuePtr builtin_dxf_dim(const Context *ctx, const EvalContext *evalctx)

View file

@ -1,7 +1,7 @@
#pragma once
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include "value.h"
extern boost::unordered_map<std::string, ValuePtr> dxf_dim_cache;
extern boost::unordered_map<std::string, ValuePtr> dxf_cross_cache;
extern std::unordered_map<std::string, ValuePtr> dxf_dim_cache;
extern std::unordered_map<std::string, ValuePtr> dxf_cross_cache;

View file

@ -1,19 +0,0 @@
#include "grid.h"
namespace Eigen {
size_t hash_value(Vector3f const &v) {
size_t seed = 0;
for (int i=0;i<3;i++) boost::hash_combine(seed, v[i]);
return seed;
}
size_t hash_value(Vector3d const &v) {
size_t seed = 0;
for (int i=0;i<3;i++) boost::hash_combine(seed, v[i]);
return seed;
}
size_t hash_value(Eigen::Matrix<int64_t, 3, 1> const &v) {
size_t seed = 0;
for (int i=0;i<3;i++) boost::hash_combine(seed, v[i]);
return seed;
}
}

View file

@ -2,6 +2,8 @@
#include "mathc99.h"
#include "linalg.h"
#include "hash.h"
#include <boost/functional/hash.hpp>
#ifdef _WIN32
typedef __int64 int64_t;
@ -9,7 +11,7 @@ typedef __int64 int64_t;
#include <stdint.h>
#endif
#include <stdlib.h>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <utility>
//const double GRID_COARSE = 0.001;
@ -27,7 +29,7 @@ class Grid2d
{
public:
double res;
boost::unordered_map<std::pair<int64_t,int64_t>, T> db;
std::unordered_map<std::pair<int64_t,int64_t>, T, boost::hash<std::pair<int64_t,int64_t>>> db;
Grid2d(double resolution) {
res = resolution;
@ -87,21 +89,13 @@ public:
}
};
typedef Eigen::Matrix<int64_t, 3, 1> Vector3l;
namespace Eigen {
size_t hash_value(Vector3f const &v);
size_t hash_value(Vector3d const &v);
size_t hash_value(Vector3l const &v);
}
template <typename T>
class Grid3d
{
public:
double res;
typedef Vector3l Key;
typedef boost::unordered_map<Key, T> GridContainer;
typedef std::unordered_map<Key, T> GridContainer;
GridContainer db;
Grid3d(double resolution) {

View file

@ -2,13 +2,13 @@
#include <string>
#include <sstream>
#include <stdlib.h> // for system()
#include <boost/unordered_set.hpp>
#include <unordered_set>
#include <boost/regex.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include "boosty.h"
boost::unordered_set<std::string> dependencies;
std::unordered_set<std::string> dependencies;
const char *make_command = NULL;
void handle_dep(const std::string &filename)

32
src/hash.cc Normal file
View file

@ -0,0 +1,32 @@
#include "hash.h"
#include <boost/functional/hash.hpp>
namespace std {
std::size_t hash<Vector3f>::operator()(const Vector3f &s) const {
return Eigen::hash_value(s);
}
std::size_t hash<Vector3d>::operator()(const Vector3d &s) const {
return Eigen::hash_value(s);
}
std::size_t hash<Vector3l>::operator()(const Vector3l &s) const {
return Eigen::hash_value(s);
}
}
namespace Eigen {
size_t hash_value(Vector3f const &v) {
size_t seed = 0;
for (int i=0;i<3;i++) boost::hash_combine(seed, v[i]);
return seed;
}
size_t hash_value(Vector3d const &v) {
size_t seed = 0;
for (int i=0;i<3;i++) boost::hash_combine(seed, v[i]);
return seed;
}
size_t hash_value(Eigen::Matrix<int64_t, 3, 1> const &v) {
size_t seed = 0;
for (int i=0;i<3;i++) boost::hash_combine(seed, v[i]);
return seed;
}
}

17
src/hash.h Normal file
View file

@ -0,0 +1,17 @@
#pragma once
#include "linalg.h"
typedef Eigen::Matrix<int64_t, 3, 1> Vector3l;
namespace std {
template<> struct hash<Vector3f> { std::size_t operator()(const Vector3f &s) const; };
template<> struct hash<Vector3d> { std::size_t operator()(const Vector3d &s) const; };
template<> struct hash<Vector3l> { std::size_t operator()(const Vector3l &s) const; };
}
namespace Eigen {
size_t hash_value(Vector3f const &v);
size_t hash_value(Vector3d const &v);
size_t hash_value(Vector3l const &v);
}

View file

@ -1,7 +1,7 @@
#pragma once
#include "typedefs.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
class LocalScope
{
@ -17,8 +17,8 @@ public:
AssignmentList assignments;
ModuleInstantiationList children;
typedef boost::unordered_map<std::string, class AbstractFunction*> FunctionContainer;
typedef std::unordered_map<std::string, class AbstractFunction*> FunctionContainer;
FunctionContainer functions;
typedef boost::unordered_map<std::string, class AbstractModule*> AbstractModuleContainer;
typedef std::unordered_map<std::string, class AbstractModule*> AbstractModuleContainer;
AbstractModuleContainer modules;
};

View file

@ -31,7 +31,7 @@ void ModuleContext::evaluateAssignments(const AssignmentList &assignments)
// Variables which couldn't be evaluated in the first pass is attempted again,
// to allow for initialization out of order
boost::unordered_map<std::string, Expression *> tmpass;
std::unordered_map<std::string, Expression *> tmpass;
for(const auto &ass : assignments) {
tmpass[ass.first] = ass.second;
}
@ -42,7 +42,7 @@ void ModuleContext::evaluateAssignments(const AssignmentList &assignments)
std::list<std::string>::iterator iter = undefined_vars.begin();
while (iter != undefined_vars.end()) {
std::list<std::string>::iterator curr = iter++;
boost::unordered_map<std::string, Expression *>::iterator found = tmpass.find(*curr);
std::unordered_map<std::string, Expression *>::iterator found = tmpass.find(*curr);
if (found != tmpass.end()) {
const Expression *expr = found->second;
ValuePtr tmpval = expr->evaluate(this);

View file

@ -2,7 +2,6 @@
#include "context.h"
#include "module.h"
#include <boost/unordered_map.hpp>
/*!
This holds the context for a Module definition; keeps track of

View file

@ -4,8 +4,8 @@
#include <vector>
#include <list>
#include <deque>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <sys/stat.h>
@ -121,7 +121,7 @@ public:
bool isHandlingDependencies() const { return this->is_handling_dependencies; }
ValuePtr lookup_variable(const std::string &name) const;
typedef boost::unordered_set<std::string> ModuleContainer;
typedef std::unordered_set<std::string> ModuleContainer;
ModuleContainer usedlibs;
private:
/** Reference to retain the context that was used in the last evaluation */
@ -134,7 +134,7 @@ private:
bool include_modified(const IncludeFile &inc) const;
typedef boost::unordered_map<std::string, struct IncludeFile> IncludeContainer;
typedef std::unordered_map<std::string, struct IncludeFile> IncludeContainer;
IncludeContainer includes;
bool is_handling_dependencies;
std::string path;

View file

@ -37,7 +37,8 @@
#include <sstream>
#include <fstream>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <boost/functional/hash.hpp>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
@ -54,7 +55,7 @@ public:
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const;
};
typedef boost::unordered_map<std::pair<int,int>,double> img_data_t;
typedef std::unordered_map<std::pair<int,int>, double, boost::hash<std::pair<int,int>>> img_data_t;
class SurfaceNode : public LeafNode
{