← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3885: Some cosmetic fixes in core-files.

 

------------------------------------------------------------
revno: 3885
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
timestamp: Thu 2016-06-02 20:06:44 +0200
message:
  Some cosmetic fixes in core-files.
modified:
  core/Body.cpp
  core/Body.hpp
  core/BodyContainer.cpp
  core/BodyContainer.hpp
  core/Scene.cpp
  core/Scene.hpp
  core/State.hpp
  py/wrapper/yadeWrapper.cpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'core/Body.cpp'
--- core/Body.cpp	2014-10-15 06:44:01 +0000
+++ core/Body.cpp	2016-06-02 18:06:44 +0000
@@ -21,9 +21,9 @@
 }
 
 // return list of interactions of this particle
-unsigned int Body::coordNumber(){
+const unsigned int Body::coordNumber() const {
 	unsigned int intrSize = 0;
-	for(Body::MapId2IntrT::iterator it=this->intrs.begin(),end=this->intrs.end(); it!=end; ++it) {  //Iterate over all bodie's interactions
+	for(auto it=this->intrs.begin(),end=this->intrs.end(); it!=end; ++it) {  //Iterate over all bodie's interactions
 		if(!(*it).second->isReal()) continue;
 		intrSize++;
 	}

=== modified file 'core/Body.hpp'
--- core/Body.hpp	2015-11-18 07:06:16 +0000
+++ core/Body.hpp	2016-06-02 18:06:44 +0000
@@ -9,14 +9,14 @@
 *************************************************************************/
 #pragma once
 
-#include"Shape.hpp"
-#include"Bound.hpp"
-#include"State.hpp"
-#include"Material.hpp"
+#include "Shape.hpp"
+#include "Bound.hpp"
+#include "State.hpp"
+#include "Material.hpp"
 
-#include<lib/base/Math.hpp>
-#include<lib/serialization/Serializable.hpp>
-#include<lib/multimethods/Indexable.hpp>
+#include <lib/base/Math.hpp>
+#include <lib/serialization/Serializable.hpp>
+#include <lib/multimethods/Indexable.hpp>
 
 class Scene;
 class Interaction;
@@ -24,9 +24,9 @@
 class Body: public Serializable{
 	public:
 		// numerical types for storing ids
-		typedef int id_t;
+		using id_t = int ;
 		// internal structure to hold some interaction of a body; used by InteractionContainer;
-		typedef std::map<Body::id_t, shared_ptr<Interaction> > MapId2IntrT;
+		using MapId2IntrT = std::map<Body::id_t, shared_ptr<Interaction> >;
 		// groupMask type
 
 		// bits for Body::flags
@@ -63,9 +63,9 @@
 		boost::python::list py_intrs();
 
 		Body::id_t getId() const {return id;};
-		unsigned int coordNumber();  // Number of neighboring particles
+		const unsigned int coordNumber() const;  // Number of neighboring particles
 
-		mask_t getGroupMask() const {return groupMask; };
+		const mask_t getGroupMask() const {return groupMask; };
 		bool maskOk(int mask) const;
 		bool maskCompatible(int mask) const;
 #ifdef YADE_MASK_ARBITRARY

=== modified file 'core/BodyContainer.cpp'
--- core/BodyContainer.cpp	2015-11-18 07:06:16 +0000
+++ core/BodyContainer.cpp	2016-06-02 18:06:44 +0000
@@ -14,7 +14,7 @@
 	body.clear();
 }
 
-Body::id_t BodyContainer::insert(shared_ptr<Body>& b){
+Body::id_t BodyContainer::insert(shared_ptr<Body> b){
 	const shared_ptr<Scene>& scene=Omega::instance().getScene(); 
 	b->iterBorn=scene->iter;
 	b->timeBorn=scene->time;
@@ -41,8 +41,8 @@
 		const shared_ptr<Clump>& clump=YADE_PTR_CAST<Clump>(b->shape);
 		std::map<Body::id_t,Se3r>& members = clump->members;
 		std::vector<Body::id_t> idsToRemove;
-		FOREACH(MemberMap::value_type mm, members) idsToRemove.push_back(mm.first); // Prepare an array of ids, which need to be removed.
-		FOREACH(Body::id_t memberId, idsToRemove){
+		for(const auto mm : members) idsToRemove.push_back(mm.first); // Prepare an array of ids, which need to be removed.
+		for(Body::id_t memberId : idsToRemove){
 			if (eraseClumpMembers) {
 				this->erase(memberId,false);	// erase members
 			} else {
@@ -54,7 +54,7 @@
 		return true;
 	}
 	const shared_ptr<Scene>& scene=Omega::instance().getScene();
-	for(Body::MapId2IntrT::iterator it=b->intrs.begin(),end=b->intrs.end(); it!=end; ++it) {  //Iterate over all body's interactions
+	for(auto it=b->intrs.begin(), end=b->intrs.end(); it!=end; ++it) {  //Iterate over all body's interactions
 		scene->interactions->requestErase((*it).second);
 	}
 	b->id=-1;//else it sits in the python scope without a chance to be inserted again

=== modified file 'core/BodyContainer.hpp'
--- core/BodyContainer.hpp	2015-11-18 07:06:16 +0000
+++ core/BodyContainer.hpp	2016-06-02 18:06:44 +0000
@@ -4,8 +4,8 @@
 
 #pragma once
 
-#include<lib/serialization/Serializable.hpp>
-#include<boost/tuple/tuple.hpp>
+#include <lib/serialization/Serializable.hpp>
+#include <boost/tuple/tuple.hpp>
 
 class Body;
 class InteractionContainer;
@@ -27,8 +27,8 @@
 */
 class BodyContainer: public Serializable{
 	private:
-		typedef std::vector<shared_ptr<Body> > ContainerT;
-		typedef std::map<Body::id_t,Se3r> MemberMap;
+		using ContainerT = std::vector<shared_ptr<Body> > ;
+		using MemberMap = std::map<Body::id_t,Se3r> ;
 		ContainerT body;
 	public:
 		friend class InteractionContainer;  // accesses the body vector directly
@@ -48,12 +48,12 @@
 			smart_iterator(const ContainerT::iterator& source) {(*this)=source;}
 			smart_iterator(const smart_iterator& source) {(*this)=source; end=source.end;}
 		};
-		typedef smart_iterator iterator;
-		typedef const smart_iterator const_iterator;
+		using iterator = smart_iterator ;
+		using const_iterator = const smart_iterator ;
 
 		BodyContainer() {};
 		virtual ~BodyContainer() {};
-		Body::id_t insert(shared_ptr<Body>&);
+		Body::id_t insert(shared_ptr<Body>);
 		void clear();
 		iterator begin() {
 			iterator temp(body.begin());
@@ -65,11 +65,13 @@
 			return temp;
 		}
 
-		size_t size() const { return body.size(); }
+		const size_t size() const { return body.size(); }
 		shared_ptr<Body>& operator[](unsigned int id){ return body[id];}
 		const shared_ptr<Body>& operator[](unsigned int id) const { return body[id]; }
 
-		bool exists(Body::id_t id) const { return (id>=0) && ((size_t)id<body.size()) && ((bool)body[id]); }
+		const bool exists(Body::id_t id) const {
+			return ((id>=0) && ((size_t)id<body.size()) && ((bool)body[id]));
+		}
 		bool erase(Body::id_t id, bool eraseClumpMembers);
 		
 		REGISTER_CLASS_AND_BASE(BodyContainer,Serializable);

=== modified file 'core/Scene.cpp'
--- core/Scene.cpp	2014-10-15 06:44:01 +0000
+++ core/Scene.cpp	2016-06-02 18:06:44 +0000
@@ -9,22 +9,18 @@
 *************************************************************************/
 
 #include"Scene.hpp"
-#include<core/Engine.hpp>
-#include<core/Timing.hpp>
-#include<core/TimeStepper.hpp>
-
-#include<lib/base/Math.hpp>
-#include<boost/date_time/posix_time/posix_time.hpp>
-#include<boost/algorithm/string.hpp>
-
-#include<core/BodyContainer.hpp>
-#include<core/InteractionContainer.hpp>
-
-
-// POSIX-only
-#include<pwd.h>
-#include<unistd.h>
-#include<time.h>
+
+#include <lib/base/Math.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/algorithm/string.hpp>
+
+#include <core/BodyContainer.hpp>
+#include <core/InteractionContainer.hpp>
+#include <core/TimeStepper.hpp>
+
+#include <pwd.h>
+#include <unistd.h>
+#include <time.h>
 
 namespace py=boost::python;
 
@@ -36,8 +32,8 @@
 void Scene::fillDefaultTags(){
 	// fill default tags
 	struct passwd* pw;
-	char hostname[HOST_NAME_MAX];
-	gethostname(hostname,HOST_NAME_MAX);
+	char hostname[hostNameMax];
+	gethostname(hostname,hostNameMax);
 	pw=getpwuid(geteuid()); if(!pw) throw runtime_error("getpwuid(geteuid()) failed!");
 	// a few default tags
 	// real name: will have all non-ASCII characters replaced by ? since serialization doesn't handle that
@@ -52,8 +48,6 @@
 	// tags.push_back("revision="+py::extract<string>(py::import("yade.config").attr("revision"))());;
 }
 
-
-
 void Scene::postLoad(Scene&){
 	// update the interaction container; must be done in Scene ctor as well; important!
 	interactions->postLoad__calledFromScene(bodies);
@@ -65,8 +59,6 @@
 	}
 }
 
-
-
 void Scene::moveToNextTimeStep(){
 	if(runInternalConsistencyChecks){
 		runInternalConsistencyChecks=false;
@@ -137,8 +129,6 @@
 	}
 }
 
-
-
 shared_ptr<Engine> Scene::engineByName(const string& s){
 	FOREACH(shared_ptr<Engine> e, engines){
 		if(e->getClassName()==s) return e;
@@ -172,8 +162,6 @@
 	return n>0;
 }
 
-
-
 void Scene::checkStateTypes(){
 	FOREACH(const shared_ptr<Body>& b, *bodies){
 		if(!b || !b->material) continue;
@@ -204,4 +192,3 @@
 	bound->min=mn; 
 	bound->max=mx;
 }
-

=== modified file 'core/Scene.hpp'
--- core/Scene.hpp	2015-12-06 09:19:36 +0000
+++ core/Scene.hpp	2016-06-02 18:06:44 +0000
@@ -10,19 +10,16 @@
 
 #pragma once
 
-#include<core/Body.hpp>
-#include<core/Cell.hpp>
-#include<core/BodyContainer.hpp>
-#include<core/Engine.hpp>
-#include<core/Material.hpp>
-#include<core/DisplayParameters.hpp>
-#include<core/ForceContainer.hpp>
-#include<core/InteractionContainer.hpp>
-#include<core/EnergyTracker.hpp>
+#include <core/Body.hpp>
+#include <core/Cell.hpp>
+#include <core/BodyContainer.hpp>
+#include <core/Engine.hpp>
+#include <core/Material.hpp>
+#include <core/DisplayParameters.hpp>
+#include <core/ForceContainer.hpp>
+#include <core/InteractionContainer.hpp>
+#include <core/EnergyTracker.hpp>
 
-#ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 255 
-#endif
 #ifdef YADE_OPENMP
 	#include<omp.h>
 #endif
@@ -33,6 +30,8 @@
 #endif
 
 class Scene: public Serializable{
+	const unsigned int hostNameMax = 255;
+	
 	public:
 		//! Adds material to Scene::materials. It also sets id of the material accordingly and returns it.
 		int addMaterial(shared_ptr<Material> m){ materials.push_back(m); m->id=(int)materials.size()-1; return m->id; }
@@ -59,7 +58,6 @@
 		static const int nSpeedIter = 10;       //Number of iterations, which are taking into account for speed calculation
 		Eigen::Matrix<Real,nSpeedIter,1> SpeedElements; //Array for saving speed-values for last "nSpeedIter"-iterations
 
-
 		shared_ptr<Engine> engineByName(const string& s);
 
 		#ifdef YADE_LIQMIGRATION

=== modified file 'core/State.hpp'
--- core/State.hpp	2015-11-18 07:06:16 +0000
+++ core/State.hpp	2016-06-02 18:06:44 +0000
@@ -33,14 +33,14 @@
 		void blockedDOFs_vec_set(const std::string& dofs);
 
 		//! Return displacement (current-reference position)
-		Vector3r displ() const {return pos-refPos;}
+		const Vector3r displ() const {return pos-refPos;}
 		//! Return rotation (current-reference orientation, as Vector3r)
-		Vector3r rot() const { Quaternionr relRot=refOri.conjugate()*ori; AngleAxisr aa(relRot); return aa.axis()*aa.angle(); }
+		const Vector3r rot() const { Quaternionr relRot=refOri.conjugate()*ori; AngleAxisr aa(relRot); return aa.axis()*aa.angle(); }
 
 		// python access functions: pos and ori are references to inside Se3r and cannot be pointed to directly
-		Vector3r pos_get() const {return pos;}
+		const Vector3r pos_get() const {return pos;}
 		void pos_set(const Vector3r p) {pos=p;}
-		Quaternionr ori_get() const {return ori; }
+		const Quaternionr ori_get() const {return ori; }
 		void ori_set(const Quaternionr o){ori=o;}
 
 	YADE_CLASS_BASE_DOC_ATTRS_INIT_CTOR_PY(State,Serializable,"State of a body (spatial configuration, internal variables).",

=== modified file 'py/wrapper/yadeWrapper.cpp'
--- py/wrapper/yadeWrapper.cpp	2016-03-24 21:50:26 +0000
+++ py/wrapper/yadeWrapper.cpp	2016-06-02 18:06:44 +0000
@@ -322,7 +322,7 @@
 					R2 = 0.0; dens = 0.0; vol = 0.0;
 					const shared_ptr<Clump>& clump=YADE_PTR_CAST<Clump>(b->shape);
 					std::map<Body::id_t,Se3r>& members = clump->members;
-					FOREACH(MemberMap::value_type& mm, members){
+					for(MemberMap::value_type& mm : members){
 						const Body::id_t& memberId=mm.first;
 						const shared_ptr<Body>& member=Body::byId(memberId,scene);
 						assert(member->isClumpMember());