Commit bf3d5ed2 authored by Anton Gladky's avatar Anton Gladky
Browse files

Remove all "using namespace std;"

parent 5cf60e4d
......@@ -54,7 +54,7 @@ Body::id_t BodyContainer::insert(shared_ptr<Body>& b, Body::id_t id){
bool BodyContainer::erase(Body::id_t id, bool eraseClumpMembers){//default is false (as before)
if(!exists(id)) return false;
lowestFree=min(lowestFree,id);
lowestFree=std::min(lowestFree,id);
const shared_ptr<Body>& b=Body::byId(id);
......
......@@ -13,7 +13,7 @@ void Cell::integrateAndUpdate(Real dt){
prevHSize=hSize;
_vGradTimesPrevH = velGrad*prevHSize;
hSize+=_trsfInc*hSize;
if(hSize.determinant()==0){ throw runtime_error("Cell is degenerate (zero volume)."); }
if(hSize.determinant()==0){ throw std::runtime_error("Cell is degenerate (zero volume)."); }
// lengths of transformed cell vectors, skew cosines
Matrix3r Hnorm; // normalized transformed base vectors
for(int i=0; i<3; i++){
......
......@@ -124,7 +124,7 @@ void Clump::updateProperties(const shared_ptr<Body>& clumpBody, unsigned int dis
const Sphere* sphere1 = YADE_CAST<Sphere*> (subBody1->shape.get());
const Sphere* sphere2 = YADE_CAST<Sphere*> (subBody2->shape.get());
Real un = (sphere1->radius+sphere2->radius) - dist.norm();
if (un > 0.001*min(sphere1->radius,sphere2->radius)) {intersecting = true; break;}
if (un > 0.001*std::min(sphere1->radius,sphere2->radius)) {intersecting = true; break;}
}
}
if (intersecting) break;
......@@ -153,7 +153,7 @@ void Clump::updateProperties(const shared_ptr<Body>& clumpBody, unsigned int dis
const Sphere* sphere = YADE_CAST<Sphere*> (subBody->shape.get());
aabb.extend(subBody->state->pos + Vector3r::Constant(sphere->radius));
aabb.extend(subBody->state->pos - Vector3r::Constant(sphere->radius));
rMin=min(rMin,sphere->radius);
rMin=std::min(rMin,sphere->radius);
}
}
//get volume and inertia tensor using regular cubic cell array inside bounding box of the clump:
......
......@@ -46,7 +46,7 @@ Because we need literal functor and class names for registration in python, we p
BOOST_PP_CAT(_YADE_DISPATCHER,BOOST_PP_CAT(Dim,D_FUNCTOR_ADD))(FunctorT,f) \
boost::python::list functors_get(void) const { boost::python::list ret; FOREACH(const shared_ptr<FunctorT>& f, functors){ ret.append(f); } return ret; } \
void functors_set(const vector<shared_ptr<FunctorT> >& ff){ functors.clear(); FOREACH(const shared_ptr<FunctorT>& f, ff) add(f); postLoad(*this); } \
void pyHandleCustomCtorArgs(boost::python::tuple& t, boost::python::dict& d){ if(boost::python::len(t)==0)return; if(boost::python::len(t)!=1) throw invalid_argument("Exactly one list of " BOOST_PP_STRINGIZE(FunctorT) " must be given."); typedef std::vector<shared_ptr<FunctorT> > vecF; vecF vf=boost::python::extract<vecF>(t[0])(); functors_set(vf); t=boost::python::tuple(); } \
void pyHandleCustomCtorArgs(boost::python::tuple& t, boost::python::dict& d){ if(boost::python::len(t)==0)return; if(boost::python::len(t)!=1) throw std::invalid_argument("Exactly one list of " BOOST_PP_STRINGIZE(FunctorT) " must be given."); typedef std::vector<shared_ptr<FunctorT> > vecF; vecF vf=boost::python::extract<vecF>(t[0])(); functors_set(vf); t=boost::python::tuple(); } \
YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(DispatcherT,Dispatcher,"Dispatcher calling :yref:`functors<" BOOST_PP_STRINGIZE(FunctorT) ">` based on received argument type(s).\n\n" doc, \
((vector<shared_ptr<FunctorT> >,functors,,,"Functors active in the dispatch mechanism [overridden below].")) /*additional attrs*/ attrs, \
/*ctor*/ ctor, /*py*/ py .add_property("functors",&DispatcherT::functors_get,&DispatcherT::functors_set,"Functors associated with this dispatcher." " :yattrtype:`vector<shared_ptr<" BOOST_PP_STRINGIZE(FunctorT) "> >` ") \
......@@ -74,12 +74,12 @@ std::string Dispatcher_indexToClassName(int idx){
shared_ptr<topIndexable> inst=YADE_PTR_DYN_CAST<topIndexable>(ClassFactory::instance().createShared(clss.first));
assert(inst);
if(inst->getClassIndex()<0 && inst->getClassName()!=top->getClassName()){
throw logic_error("Class "+inst->getClassName()+" didn't use REGISTER_CLASS_INDEX("+inst->getClassName()+","+top->getClassName()+") and/or forgot to call createIndex() in the ctor. [[ Please fix that! ]]");
throw std::logic_error("Class "+inst->getClassName()+" didn't use REGISTER_CLASS_INDEX("+inst->getClassName()+","+top->getClassName()+") and/or forgot to call createIndex() in the ctor. [[ Please fix that! ]]");
}
if(inst->getClassIndex()==idx) return clss.first;
}
}
throw runtime_error("No class with index "+boost::lexical_cast<string>(idx)+" found (top-level indexable is "+topName+")");
throw std::runtime_error("No class with index "+boost::lexical_cast<string>(idx)+" found (top-level indexable is "+topName+")");
}
//! Return class index of given indexable
......@@ -107,7 +107,7 @@ boost::python::list Indexable_getClassIndices(const shared_ptr<TopIndexable> i,
template<typename DispatcherT>
std::vector<shared_ptr<typename DispatcherT::functorType> > Dispatcher_functors_get(shared_ptr<DispatcherT> self){
std::vector<shared_ptr<typename DispatcherT::functorType> > ret;
FOREACH(const shared_ptr<Functor>& functor, self->functors){ shared_ptr<typename DispatcherT::functorType> functorRightType(YADE_PTR_DYN_CAST<typename DispatcherT::functorType>(functor)); if(!functorRightType) throw logic_error("Internal error: Dispatcher of type "+self->getClassName()+" did not contain Functor of the required type "+typeid(typename DispatcherT::functorType).name()+"?"); ret.push_back(functorRightType); }
FOREACH(const shared_ptr<Functor>& functor, self->functors){ shared_ptr<typename DispatcherT::functorType> functorRightType(YADE_PTR_DYN_CAST<typename DispatcherT::functorType>(functor)); if(!functorRightType) throw std::logic_error("Internal error: Dispatcher of type "+self->getClassName()+" did not contain Functor of the required type "+typeid(typename DispatcherT::functorType).name()+"?"); ret.push_back(functorRightType); }
return ret;
}
......
......@@ -14,7 +14,7 @@
CREATE_LOGGER(FileGenerator);
bool FileGenerator::generate(std::string& msg){ throw invalid_argument("Calling abstract FileGenerator::generate() does not make sense."); }
bool FileGenerator::generate(std::string& msg){ throw std::invalid_argument("Calling abstract FileGenerator::generate() does not make sense."); }
bool FileGenerator::generateAndSave(const string& outputFileName, string& message)
......
......@@ -63,15 +63,15 @@ class ForceContainer{
inline void ensureSize(Body::id_t id, int threadN){
assert(nThreads>omp_get_thread_num());
const Body::id_t idMaxTmp = max(id, _maxId[threadN]);
const Body::id_t idMaxTmp = std::max(id, _maxId[threadN]);
_maxId[threadN] = 0;
if (threadN<0) {
resizePerm(min((size_t)1.5*(idMaxTmp+100),(size_t)(idMaxTmp+2000)));
resizePerm(std::min((size_t)1.5*(idMaxTmp+100),(size_t)(idMaxTmp+2000)));
} else if (sizeOfThreads[threadN]<=(size_t)idMaxTmp) {
resize(min((size_t)1.5*(idMaxTmp+100),(size_t)(idMaxTmp+2000)),threadN);
resize(std::min((size_t)1.5*(idMaxTmp+100),(size_t)(idMaxTmp+2000)),threadN);
}
}
inline void ensureSynced(){ if(!synced) throw runtime_error("ForceContainer not thread-synchronized; call sync() first!"); }
inline void ensureSynced(){ if(!synced) throw std::runtime_error("ForceContainer not thread-synchronized; call sync() first!"); }
// dummy function to avoid template resolution failure
friend class boost::serialization::access; template<class ArchiveT> void serialize(ArchiveT & ar, unsigned int version){}
......@@ -228,9 +228,9 @@ class ForceContainer {
size_t size;
size_t permSize;
inline void ensureSize(Body::id_t id){
const Body::id_t idMaxTmp = max(id, _maxId);
const Body::id_t idMaxTmp = std::max(id, _maxId);
_maxId = 0;
if(size<=(size_t)idMaxTmp) resize(min((size_t)1.5*(idMaxTmp+100),(size_t)(idMaxTmp+2000)));
if(size<=(size_t)idMaxTmp) resize(std::min((size_t)1.5*(idMaxTmp+100),(size_t)(idMaxTmp+2000)));
}
#if 0
const Vector3r& getForceUnsynced (Body::id_t id){ return getForce(id);}
......
......@@ -51,7 +51,7 @@ class Functor1D: public Functor,
public:
typedef _DispatchType1 DispatchType1; typedef _ReturnType ReturnType; typedef _ArgumentTypes ArgumentTypes;
#define FUNCTOR1D(type1) public: std::string get1DFunctorType1(void){return string(#type1);} int checkArgTypes(const shared_ptr<DispatchType1>& arg1){ return (bool)YADE_PTR_DYN_CAST<type1>(arg1)?1:0; }
virtual std::string get1DFunctorType1(void){throw runtime_error("Class "+this->getClassName()+" did not use FUNCTOR1D to declare its argument type?"); }
virtual std::string get1DFunctorType1(void){throw std::runtime_error("Class "+this->getClassName()+" did not use FUNCTOR1D to declare its argument type?"); }
virtual vector<string> getFunctorTypes(void){vector<string> ret; ret.push_back(get1DFunctorType1()); return ret;};
// check that the object can be correctly cast to the derived class handled by the functor (will be used if ever utils.createInteraction can be called with list of functors only)
// virtual bool checkArgTypes(const shared_ptr<DispatchType1>& arg1){ throw runtime_error("Class "+this->getClassName()+" did not use FUNCTOR1D to declare its argument type?"); }
......@@ -73,8 +73,8 @@ class Functor2D: public Functor,
public:
typedef _DispatchType1 DispatchType1; typedef _DispatchType2 DispatchType2; typedef _ReturnType ReturnType; typedef _ArgumentTypes ArgumentTypes;
#define FUNCTOR2D(type1,type2) public: std::string get2DFunctorType1(void){return string(#type1);}; std::string get2DFunctorType2(void){return string(#type2);}; int checkArgTypes(const shared_ptr<DispatchType1>& arg1, const shared_ptr<DispatchType2>& arg2){ if(YADE_PTR_DYN_CAST<type1>(arg1)&&YADE_PTR_DYN_CAST<type2>(arg2)) return 1; if(YADE_PTR_DYN_CAST<type1>(arg2)&&YADE_PTR_DYN_CAST<type2>(arg1)) return -1; return 0; }
virtual std::string get2DFunctorType1(void){throw logic_error("Class "+this->getClassName()+" did not use FUNCTOR2D to declare its argument types?");}
virtual std::string get2DFunctorType2(void){throw logic_error("Class "+this->getClassName()+" did not use FUNCTOR2D to declare its argument types?");}
virtual std::string get2DFunctorType1(void){throw std::logic_error("Class "+this->getClassName()+" did not use FUNCTOR2D to declare its argument types?");}
virtual std::string get2DFunctorType2(void){throw std::logic_error("Class "+this->getClassName()+" did not use FUNCTOR2D to declare its argument types?");}
virtual vector<string> getFunctorTypes(){vector<string> ret; ret.push_back(get2DFunctorType1()); ret.push_back(get2DFunctorType2()); return ret;};
// check that objects can be correctly cast to derived classes handled by the functor (see comment in Functor1D:: checkArgTypes)
// virtual bool checkArgTypes(const shared_ptr<DispatchType1>&, const shared_ptr<DispatchType2>&){ throw logic_error("Class "+this->getClassName()+" did not use FUNCTOR2D to declare its argument types?"); }
......
......@@ -17,7 +17,7 @@ bool InteractionContainer::insert(const shared_ptr<Interaction>& i){
Body::id_t id1=i->getId1();
Body::id_t id2=i->getId2();
if (id1>id2) swap(id1,id2);
if (id1>id2) std::swap(id1,id2);
assert((Body::id_t)bodies->size()>id1); // the bodies must exist already
assert((Body::id_t)bodies->size()>id2);
......@@ -54,7 +54,7 @@ void InteractionContainer::clear(){
bool InteractionContainer::erase(Body::id_t id1,Body::id_t id2, int linPos){
assert(bodies);
boost::mutex::scoped_lock lock(drawloopmutex);
if (id1>id2) swap(id1,id2);
if (id1>id2) std::swap(id1,id2);
if(id2>=(Body::id_t)bodies->size()) return false; // no such interaction
const shared_ptr<Body>& b1((*bodies)[id1]);
......@@ -95,7 +95,7 @@ bool InteractionContainer::erase(Body::id_t id1,Body::id_t id2, int linPos){
const shared_ptr<Interaction>& InteractionContainer::find(Body::id_t id1,Body::id_t id2){
assert(bodies);
if (id1>id2) swap(id1,id2);
if (id1>id2) std::swap(id1,id2);
// those checks could be perhaps asserts, but pyInteractionContainer has no access to the body container...
if(id2>=(Body::id_t)bodies->size()){ empty=shared_ptr<Interaction>(); return empty; }
const shared_ptr<Body>& b1((*bodies)[id1]);
......
......@@ -46,7 +46,7 @@ class RenderMutexLock: public boost::mutex::scoped_lock{
CREATE_LOGGER(Omega);
SINGLETON_SELF(Omega);
const map<string,DynlibDescriptor>& Omega::getDynlibsDescriptor(){return dynlibs;}
const std::map<string,DynlibDescriptor>& Omega::getDynlibsDescriptor(){return dynlibs;}
const shared_ptr<Scene>& Omega::getScene(){return scenes.at(currentSceneNb);}
void Omega::resetCurrentScene(){ RenderMutexLock lock; scenes.at(currentSceneNb) = shared_ptr<Scene>(new Scene);}
......@@ -164,28 +164,28 @@ void Omega::buildDynlibDatabase(const vector<string>& dynlibsList){
for now, just loop until we succeed; proper solution will be to build graphs of classes
and traverse it from the top. It will be done once all classes are pythonable. */
for(int i=0; i<100 && pythonables.size()>0; i++){
if(getenv("YADE_DEBUG")) cerr<<endl<<"[[[ Round "<<i<<" ]]]: ";
if(getenv("YADE_DEBUG")) std::cerr<<std::endl<<"[[[ Round "<<i<<" ]]]: ";
std::list<string> done;
for(std::list<string>::iterator I=pythonables.begin(); I!=pythonables.end(); ){
shared_ptr<Serializable> s=boost::static_pointer_cast<Serializable>(ClassFactory::instance().createShared(*I));
try{
if(getenv("YADE_DEBUG")) cerr<<"{{"<<*I<<"}}";
if(getenv("YADE_DEBUG")) std::cerr<<"{{"<<*I<<"}}";
s->pyRegisterClass(wrapperScope);
std::list<string>::iterator prev=I++;
pythonables.erase(prev);
} catch (...){
if(getenv("YADE_DEBUG")){ cerr<<"["<<*I<<"]"; PyErr_Print(); }
if(getenv("YADE_DEBUG")){ std::cerr<<"["<<*I<<"]"; PyErr_Print(); }
boost::python::handle_exception();
I++;
}
}
}
map<string,DynlibDescriptor>::iterator dli = dynlibs.begin();
map<string,DynlibDescriptor>::iterator dliEnd = dynlibs.end();
std::map<string,DynlibDescriptor>::iterator dli = dynlibs.begin();
std::map<string,DynlibDescriptor>::iterator dliEnd = dynlibs.end();
for( ; dli!=dliEnd ; ++dli){
set<string>::iterator bci = (*dli).second.baseClasses.begin();
set<string>::iterator bciEnd = (*dli).second.baseClasses.end();
std::set<string>::iterator bci = (*dli).second.baseClasses.begin();
std::set<string>::iterator bciEnd = (*dli).second.baseClasses.end();
for( ; bci!=bciEnd ; ++bci){
string name = *bci;
if (name=="Dispatcher1D" || name=="Dispatcher2D") (*dli).second.baseClasses.insert("Dispatcher");
......@@ -230,7 +230,7 @@ void Omega::loadPlugins(vector<string> pluginFiles){
abort();
}
}
list<string>& plugins(ClassFactory::instance().pluginClasses);
std::list<string>& plugins(ClassFactory::instance().pluginClasses);
plugins.sort(); plugins.unique();
buildDynlibDatabase(vector<string>(plugins.begin(),plugins.end()));
}
......@@ -255,7 +255,7 @@ void Omega::loadSimulation(const string& f, bool quiet){
yade::ObjectIO::load(f,"scene",scene);
}
}
if(scene->getClassName()!="Scene") throw logic_error("Wrong file format (scene is not a Scene!?) in "+f);
if(scene->getClassName()!="Scene") throw std::logic_error("Wrong file format (scene is not a Scene!?) in "+f);
sceneFile=f;
timeInit();
if(!quiet) LOG_DEBUG("Simulation loaded");
......@@ -271,7 +271,7 @@ void Omega::saveSimulation(const string& f, bool quiet){
//shared_ptr<Scene>& scene = getScene();
if(boost::algorithm::starts_with(f,":memory:")){
if(memSavedSimulations.count(f)>0 && !quiet) LOG_INFO("Overwriting in-memory saved simulation "<<f);
ostringstream oss;
std::ostringstream oss;
yade::ObjectIO::save<typeof(scene),boost::archive::binary_oarchive>(oss,"scene",scene);
memSavedSimulations[f]=oss.str();
}
......
......@@ -49,17 +49,22 @@ class Scene;
class ThreadRunner;
using namespace boost::posix_time;
using namespace std;
using std::string;
using std::vector;
using std::runtime_error;
using std::endl;
using std::cout;
using std::cerr;
struct DynlibDescriptor{
set<string> baseClasses;
std::set<string> baseClasses;
bool isIndexable, isFactorable, isSerializable;
};
class Omega: public Singleton<Omega>{
shared_ptr<ThreadRunner> simulationLoop;
SimulationFlow simulationFlow_;
map<string,DynlibDescriptor> dynlibs; // FIXME : should store that in ClassFactory ?
std::map<string,DynlibDescriptor> dynlibs; // FIXME : should store that in ClassFactory ?
void buildDynlibDatabase(const vector<string>& dynlibsList); // FIXME - maybe in ClassFactory ?
vector<shared_ptr<Scene> > scenes;
......@@ -68,7 +73,7 @@ class Omega: public Singleton<Omega>{
ptime startupLocalTime;
map<string,string> memSavedSimulations;
std::map<string,string> memSavedSimulations;
// to avoid accessing simulation when it is being loaded (should avoid crashes with the UI)
boost::mutex loadingSimulationMutex;
......@@ -83,7 +88,7 @@ class Omega: public Singleton<Omega>{
void timeInit();
void initTemps();
void cleanupTemps();
const map<string,DynlibDescriptor>& getDynlibsDescriptor();
const std::map<string,DynlibDescriptor>& getDynlibsDescriptor();
void loadPlugins(vector<string> pluginFiles);
bool isInheritingFrom(const string& className, const string& baseClassName );
bool isInheritingFrom_recursive(const string& className, const string& baseClassName );
......
......@@ -194,8 +194,8 @@ void Scene::updateBound(){
if(!b) continue;
if(b->bound){
for(int i=0; i<3; i++){
if(!std::isinf(b->bound->max[i])) mx[i]=max(mx[i],b->bound->max[i]);
if(!std::isinf(b->bound->min[i])) mn[i]=min(mn[i],b->bound->min[i]);
if(!std::isinf(b->bound->max[i])) mx[i]=std::max(mx[i],b->bound->max[i]);
if(!std::isinf(b->bound->min[i])) mn[i]=std::min(mn[i],b->bound->min[i]);
}
} else {
mx=mx.cwiseMax(b->state->pos);
......
......@@ -40,6 +40,9 @@ struct intReal {
};
#endif
using std::min;
using std::max;
class Scene: public Serializable{
public:
//! Adds material to Scene::materials. It also sets id of the material accordingly and returns it.
......@@ -106,7 +109,7 @@ class Scene: public Serializable{
((Body::id_t,selectedBody,-1,,"Id of body that is selected by the user"))
((int,flags,0,Attr::readonly,"Various flags of the scene; 1 (Scene::LOCAL_COORDS): use local coordinate system rather than global one for per-interaction quantities (set automatically from the functor)."))
((list<string>,tags,,,"Arbitrary key=value associations (tags like mp3 tags: author, date, version, description etc.)"))
((std::list<string>,tags,,,"Arbitrary key=value associations (tags like mp3 tags: author, date, version, description etc.)"))
((vector<shared_ptr<Engine> >,engines,,Attr::hidden,"Engines sequence in the simulation."))
((vector<shared_ptr<Engine> >,_nextEngines,,Attr::hidden,"Engines to be used from the next step on; is returned transparently by O.engines if in the middle of the loop (controlled by subStep>=0)."))
// NOTE: bodies must come before interactions, since InteractionContainer is initialized with a reference to BodyContainer::body
......
......@@ -16,7 +16,7 @@ CREATE_LOGGER(SimulationFlow);
void SimulationFlow::singleAction()
{
Scene* scene=Omega::instance().getScene().get();
if (!scene) throw logic_error("SimulationFlow::singleAction: no Scene object?!");
if (!scene) throw std::logic_error("SimulationFlow::singleAction: no Scene object?!");
if(scene->subStepping) { LOG_INFO("Sub-stepping disabled when running simulation continuously."); scene->subStepping=false; }
scene->moveToNextTimeStep();
if(scene->stopAtIter>0 && scene->iter==scene->stopAtIter) setTerminate(true);
......
......@@ -142,7 +142,7 @@ string GLViewer::getState(){
LOG_DEBUG("State saved to temp file "<<tmpFile);
// read tmp file contents and return it as string
// this will replace all whitespace by space (nowlines will disappear, which is what we want)
ifstream in(tmpFile.c_str()); string ret; while(!in.eof()){string ss; in>>ss; ret+=" "+ss;}; in.close();
std::ifstream in(tmpFile.c_str()); string ret; while(!in.eof()){string ss; in>>ss; ret+=" "+ss;}; in.close();
boost::filesystem::remove(boost::filesystem::path(tmpFile));
return ret;
}
......
......@@ -14,6 +14,12 @@
#include<QGLViewer/constraint.h>
#include<set>
using std::ostringstream;
using std::setfill;
using std::setw;
using std::set;
using std::setprecision;
/*! Class handling user interaction with the openGL rendering of simulation.
*
* Clipping planes:
......
......@@ -250,7 +250,7 @@ void GLViewer::postDraw(){
if(timeDispMask & GLViewer::TIME_ITER){
ostringstream oss;
oss<<"#"<<rb->iter;
if(rb->stopAtIter>rb->iter) oss<<" ("<<setiosflags(ios::fixed)<<setw(3)<<setprecision(1)<<setfill('0')<<(100.*rb->iter)/rb->stopAtIter<<"%)";
if(rb->stopAtIter>rb->iter) oss<<" ("<<setiosflags(std::ios::fixed)<<setw(3)<<setprecision(1)<<setfill('0')<<(100.*rb->iter)/rb->stopAtIter<<"%)";
QGLViewer::drawText(x,y,oss.str().c_str());
y-=lineHt;
}
......
......@@ -9,7 +9,7 @@
namespace py=boost::python;
qglviewer::Vec tuple2vec(py::tuple t){ qglviewer::Vec ret; for(int i=0;i<3;i++){py::extract<Real> e(t[i]); if(!e.check()) throw invalid_argument("Element #"+boost::lexical_cast<string>(i)+" is not a number"); ret[i]=e();} return ret;};
qglviewer::Vec tuple2vec(py::tuple t){ qglviewer::Vec ret; for(int i=0;i<3;i++){py::extract<Real> e(t[i]); if(!e.check()) throw std::invalid_argument("Element #"+boost::lexical_cast<string>(i)+" is not a number"); ret[i]=e();} return ret;};
py::tuple vec2tuple(qglviewer::Vec v){return py::make_tuple(v[0],v[1],v[2]);};
class pyGLViewer{
......@@ -44,7 +44,7 @@ class pyGLViewer{
void saveDisplayParameters(size_t n){GLV; glv->saveDisplayParameters(n);}
void useDisplayParameters(size_t n){GLV; glv->useDisplayParameters(n);}
string get_timeDisp(){GLV; const int& m(glv->timeDispMask); string ret; if(m&GLViewer::TIME_REAL) ret+='r'; if(m&GLViewer::TIME_VIRT) ret+="v"; if(m&GLViewer::TIME_ITER) ret+="i"; return ret;}
void set_timeDisp(string s){GLV; int& m(glv->timeDispMask); m=0; FOREACH(char c, s){switch(c){case 'r': m|=GLViewer::TIME_REAL; break; case 'v': m|=GLViewer::TIME_VIRT; break; case 'i': m|=GLViewer::TIME_ITER; break; default: throw invalid_argument(string("Invalid flag for timeDisp: `")+c+"'");}}}
void set_timeDisp(string s){GLV; int& m(glv->timeDispMask); m=0; FOREACH(char c, s){switch(c){case 'r': m|=GLViewer::TIME_REAL; break; case 'v': m|=GLViewer::TIME_VIRT; break; case 'i': m|=GLViewer::TIME_ITER; break; default: throw std::invalid_argument(string("Invalid flag for timeDisp: `")+c+"'");}}}
void set_bgColor(const Vector3r& c){ QColor cc(255*c[0],255*c[1],255*c[2]); GLV; glv->setBackgroundColor(cc);} Vector3r get_bgColor(){ GLV; QColor c(glv->backgroundColor()); return Vector3r(c.red()/255.,c.green()/255.,c.blue()/255.);}
#undef GLV
#undef VEC_GET_SET
......
......@@ -10,7 +10,7 @@
Look there for detailed description and more information.
*/
class ConvexHull2d{
list<Vector2r> raw_points, lower_partition_points, upper_partition_points, hull;
std::list<Vector2r> raw_points, lower_partition_points, upper_partition_points, hull;
Vector2r left, right;
static Real direction(const Vector2r& p0, const Vector2r& p1, const Vector2r& p2) {
return ((p0[0]-p1[0])*(p2[1]-p1[1]))-((p2[0]-p1[0])*(p0[1]-p1[1]));
......@@ -28,7 +28,7 @@ class ConvexHull2d{
else lower_partition_points.push_back(p);
}
}
vector<Vector2r> build_half_hull(list<Vector2r>& in, int factor){
vector<Vector2r> build_half_hull(std::list<Vector2r>& in, int factor){
vector<Vector2r> out;
in.push_back(right); out.push_back(left);
while(in.size()>0){
......@@ -42,7 +42,7 @@ class ConvexHull2d{
return out;
}
public:
ConvexHull2d(const list<Vector2r>& pts){raw_points.assign(pts.begin(),pts.end());};
ConvexHull2d(const std::list<Vector2r>& pts){raw_points.assign(pts.begin(),pts.end());};
ConvexHull2d(const vector<Vector2r>& pts){raw_points.assign(pts.begin(),pts.end());};
vector<Vector2r> operator()(void){
partition_points();
......
......@@ -159,13 +159,13 @@ class ClassFactory : public Singleton<ClassFactory>
\param tp type info of the type to test
\param fundamental is true if the given type is fundamental (Vector3,Quaternion ...)
*/
bool isFactorable(const type_info& tp,bool& fundamental);
bool isFactorable(const std::type_info& tp,bool& fundamental);
bool load(const string& fullFileName);
std::string lastError();
void registerPluginClasses(const char* fileAndClasses[]);
list<string> pluginClasses;
std::list<string> pluginClasses;
virtual string getClassName() const { return "Factorable"; };
virtual string getBaseClassName(int ) const { return "";};
......
......@@ -18,9 +18,6 @@
#include "ClassFactory.hpp"
//using namespace std;
CREATE_LOGGER(DynLibManager);
......
......@@ -18,8 +18,9 @@
#include<yade/lib/base/Logging.hpp>
using namespace std;
using std::string;
using std::vector;
using std::istringstream;
class DynLibManager
{
......
......@@ -14,7 +14,8 @@
#include <cmath>
#include "utils.hpp"
using namespace std;
using std::pair;
using std::set;
class STLReader {
public:
......
#pragma once
#include<utility>
using namespace std;
template<class T>
pair<T,T> minmax(const T &a, const T &b)
std::pair<T,T> minmax(const T &a, const T &b)
{
return (a<b) ? pair<T,T>(a,b) : pair<T,T>(b,a);
return (a<b) ? std::pair<T,T>(a,b) : std::pair<T,T>(b,a);
}
template<class T>
......
......@@ -35,9 +35,6 @@
#include<string>
#include<ostream>
using namespace std;
struct DynLibDispatcher_Item2D{ int ix1, ix2; std::string functorName; DynLibDispatcher_Item2D(int a, int b, std::string c):ix1(a),ix2(b),functorName(c){}; };
struct DynLibDispatcher_Item1D{ int ix1 ; std::string functorName; DynLibDispatcher_Item1D(int a, std::string c):ix1(a), functorName(c){}; };
///
......@@ -182,13 +179,13 @@ class DynLibDispatcher
shared_ptr<Executor> getExecutor(shared_ptr<BaseClass1>& arg1){
int ix1;
if(arg1->getClassIndex()<0) throw runtime_error("No functor for type "+arg1->getClassName()+" (index "+boost::lexical_cast<string>(arg1->getClassIndex())+"), since the index is invalid (negative).");
if(arg1->getClassIndex()<0) throw std::runtime_error("No functor for type "+arg1->getClassName()+" (index "+boost::lexical_cast<string>(arg1->getClassIndex())+"), since the index is invalid (negative).");
if(locateMultivirtualFunctor1D(ix1,arg1)) return callBacks[ix1];
return shared_ptr<Executor>();
}
shared_ptr<Executor> getExecutor(shared_ptr<BaseClass1>& arg1, shared_ptr<BaseClass2>& arg2){
if(arg1->getClassIndex()<0 || arg2->getClassIndex()<0) throw runtime_error("No functor for types "+arg1->getClassName()+" (index "+boost::lexical_cast<string>(arg1->getClassIndex())+") + "+arg2->getClassName()+" (index "+boost::lexical_cast<string>(arg2->getClassIndex())+"), since some of the indices is invalid (negative).");
if(arg1->getClassIndex()<0 || arg2->getClassIndex()<0) throw std::runtime_error("No functor for types "+arg1->getClassName()+" (index "+boost::lexical_cast<string>(arg1->getClassIndex())+") + "+arg2->getClassName()+" (index "+boost::lexical_cast<string>(arg2->getClassIndex())+"), since some of the indices is invalid (negative).");
int ix1,ix2;
if(locateMultivirtualFunctor2D(ix1,ix2,arg1,arg2)) return callBacks[ix1][ix2];
return shared_ptr<Executor>();
......@@ -253,7 +250,7 @@ class DynLibDispatcher
callBacks[index] = executor;
#if 0
cerr <<" New class added to DynLibDispatcher 1D: " << libName << endl;
std::cerr <<" New class added to DynLibDispatcher 1D: " << libName << std::endl;
#endif
};
......@@ -320,7 +317,7 @@ class DynLibDispatcher
}
#if 0
cerr <<"Added new 2d functor "<<executor->getClassName()<<", callBacks size is "<<callBacks.size()<<","<<(callBacks.size()>0?callBacks[0].size():0)<<endl;
std::cerr <<"Added new 2d functor "<<executor->getClassName()<<", callBacks size is "<<callBacks.size()<<","<<(callBacks.size()>0?callBacks[0].size():0)<<std::endl;
#endif
}
......@@ -397,8 +394,8 @@ class DynLibDispatcher
distTooBig=false;
if(callBacks[ix1][ix2]){
if(foundIx1!=-1 && callBacks[foundIx1][foundIx2]!=callBacks[ix1][ix2]){ // we found a callback, but there already was one at this distance and it was different from the current one
cerr<<__FILE__<<":"<<__LINE__<<": ambiguous 2d dispatch ("<<"arg1="<<base1->getClassName()<<", arg2="<<base2->getClassName()<<", distance="<<dist<<"), dispatch matrix:"<<endl;
dumpDispatchMatrix2D(cerr,"AMBIGUOUS: "); throw runtime_error("Ambiguous dispatch.");
std::cerr<<__FILE__<<":"<<__LINE__<<": ambiguous 2d dispatch ("<<"arg1="<<base1->getClassName()<<", arg2="<<base2->getClassName()<<", distance="<<dist<<"), dispatch matrix:"<<std::endl;
dumpDispatchMatrix2D(std::cerr,"AMBIGUOUS: "); throw std::runtime_error("Ambiguous dispatch.");
}
foundIx1=ix1; foundIx2=ix2;
callBacks[index1][index2]=callBacks[ix1][ix2]; callBacksInfo[index1][index2]=callBacksInfo[ix1][ix2];
......
......@@ -36,7 +36,6 @@
#include<yade/lib/base/Math.hpp>
using namespace std;
// empty functions for ADL
//namespace{
template<typename T> void preLoad(T&){}; template<typename T> void postLoad(T& obj){ /* cerr<<"Generic no-op postLoad("<<typeid(T).name()<<"&) called for "<<obj.getClassName()<<std::endl; */ }
......@@ -101,7 +100,7 @@ void make_setter_postLoad(C& instance, const T& val){ instance.*A=val; /* cerr<<
#define _DEF_READWRITE_BY_VALUE_STATIC(thisClass,attr,doc) _DEF_READWRITE_BY_VALUE(thisClass,attr,doc)
// the conditional yade::py_wrap_ref should be eliminated by compiler at compile-time, as it depends only on types, not their values
// most of this could be written with templates, including flags (ints can be template args)
#define _DEF_READWRITE_CUSTOM(thisClass,attr) if(!(_ATTR_FLG(attr) & yade::Attr::hidden)){ bool _ro(_ATTR_FLG(attr) & Attr::readonly), _post(_ATTR_FLG(attr) & Attr::triggerPostLoad), _ref(yade::py_wrap_ref<typeof(thisClass::_ATTR_NAM(attr))>::value); std::string docStr(_ATTR_DOC(attr)); docStr+=" :yattrflags:`"+boost::lexical_cast<string>(_ATTR_FLG(attr))+"` "; \
#define _DEF_READWRITE_CUSTOM(thisClass,attr) if(!(_ATTR_FLG(attr) & yade::Attr::hidden)){ bool _ro(_ATTR_FLG(attr) & Attr::readonly), _post(_ATTR_FLG(attr) & Attr::triggerPostLoad), _ref(yade::py_wrap_ref<typeof(thisClass::_ATTR_NAM(attr))>::value); std::string docStr(_ATTR_DOC(attr)); docStr+=" :yattrflags:`"+boost::lexical_cast<std::string>(_ATTR_FLG(attr))+"` "; \
if ( _ref && !_ro && !_post) _classObj.def_readwrite(_ATTR_NAM_STR(attr),&thisClass::_ATTR_NAM(attr),docStr.c_str()); \
else if ( _ref && !_ro && _post) _classObj.add_property(_ATTR_NAM_STR(attr),boost::python::make_getter(&thisClass::_ATTR_NAM(attr)),make_setter_postLoad<thisClass,typeof(thisClass::_ATTR_NAM(attr)),&thisClass::_ATTR_NAM(attr)>,docStr.c_str()); \
else if ( _ref && _ro) _classObj.def_readonly(_ATTR_NAM_STR(attr),&thisClass::_ATTR_NAM(attr),docStr.c_str()); \
......@@ -157,7 +156,7 @@ void make_setter_postLoad(C& instance, const T& val){ instance.*A=val; /* cerr<<
// print warning about deprecated attribute; thisClass is type name, not string