Permalink
Browse files

Minor update to Space; added .clang-format configuration file

  • Loading branch information...
1 parent 2185601 commit 732c204be0fa13ebbbff29f79ab362afde7295d8 @mlund committed Nov 19, 2016
Showing with 122 additions and 30 deletions.
  1. +95 −0 .clang-format
  2. +27 −30 include/faunus/space.h
View
@@ -0,0 +1,95 @@
+---
+Language: Cpp
+# BasedOnStyle: WebKit
+AccessModifierOffset: -4
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: false
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+BreakBeforeBinaryOperators: All
+BreakBeforeBraces: WebKit
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 0
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '$'
+IndentCaseLabels: false
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: true
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: true
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 8
+UseTab: Never
+...
+
@@ -195,8 +195,6 @@ namespace Faunus {
*/
template<typename Tgeometry, typename Tparticle=PointParticle>
class Space {
- protected:
- std::ifstream fin;
private:
bool checkSanity(); //!< Check group length and vector sync
std::vector<Group*> g; //!< Pointers to ALL groups in the system
@@ -296,8 +294,8 @@ namespace Faunus {
MoleculeMap<ParticleVector>& molList() { return molecule; } //!< Vector of molecules
- bool save(string); //!< Save container state to disk
- bool load(string, keys=NORESIZE); //!< Load container state from disk
+ bool save(const string&); //!< Save container state to disk
+ bool load(const string&, keys= NORESIZE); //!< Load container state from disk
/** @brief insert p_vec of MolID to end of p and trial */
Group* insert(PropertyBase::Tid, const p_vec&); // inserts to trial and p
@@ -488,7 +486,7 @@ namespace Faunus {
* This will insert a particle in both `p` and `trial` vectors and
* expand or push forward groups.
*
- * @todo REMOVE, still used by `Move::AtomTracker`.
+ * @todo To be remove - do not use. Only current use is in `Move::AtomTracker::insert`.
*/
template<class Tgeometry, class Tparticle>
bool Space<Tgeometry,Tparticle>::insert(const Tparticle &a, int i) {
@@ -595,24 +593,24 @@ namespace Faunus {
}
template<class Tgeometry, class Tparticle>
- bool Space<Tgeometry,Tparticle>::save(string file) {
+ bool Space<Tgeometry,Tparticle>::save(const string &file) {
using std::numeric_limits;
if (checkSanity()) {
cout << " Writing space state file '" << file << "'. ";
- std::ofstream fout( file.c_str() );
- if (fout) {
- fout.precision( numeric_limits<double>::digits10 + 1 );
+ std::ofstream f( file.c_str() );
+ if (f) {
+ f.precision( numeric_limits<double>::digits10 + 1 );
if (std::is_base_of<Geometry::Cuboid,Tgeometry>::value)
- fout << geo.len.transpose() << "\n";
- else fout << geo.getVolume() << "\n";
- fout << p.size() << "\n";
+ f << geo.len.transpose() << "\n";
+ else f << geo.getVolume() << "\n";
+ f << p.size() << "\n";
for (auto p_i : p)
- fout << p_i << "\n";
- fout << g.size() << "\n";
+ f << p_i << "\n";
+ f << g.size() << "\n";
for (auto g_i : g)
- fout << *g_i << "\n";
- fout << "randomstate\n";
- fout << slump.eng;
+ f << *g_i << "\n";
+ f << "randomstate\n";
+ f << slump.eng;
cout << "OK!\n";
return true;
}
@@ -628,26 +626,25 @@ namespace Faunus {
* (for Grand Canonical MC)
*/
template<class Tgeometry, class Tparticle>
- bool Space<Tgeometry,Tparticle>::load(string file, keys key) {
+ bool Space<Tgeometry,Tparticle>::load(const string &file, keys key) {
using namespace textio;
cout << "Reading space state file '" << file << "'. ";
- if (checkSanity()) {
- fin.close();
- fin.open( file.c_str() );
- if (fin) {
+ if ( checkSanity() ) {
+ std::ifstream f( file.c_str() );
+ if (f) {
int n;
cout << "OK!\n";
if (std::is_base_of<Geometry::Cuboid,Tgeometry>::value) {
double x,y,z;
- fin >> x >> y >> z >> n;
+ f >> x >> y >> z >> n;
geo.setlen(Point(x,y,z));
}
else {
double vol;
- fin >> vol >> n;
+ f >> vol >> n;
geo.setVolume(vol);
}
- if (key==RESIZE && n!=(int)p.size()) {
+ if ( key==RESIZE && n!=(int)p.size() ) {
cout << indent(SUB) << "Resizing particle vector from "
<< p.size() << " --> " << n << ".\n";
p.resize(n);
@@ -657,30 +654,30 @@ namespace Faunus {
if (n == (int)p.size() ) {
for (int i=0; i<n; i++)
- p[i] << fin;
+ p[i] << f;
trial=p;
cout << indent(SUB) << "Read " << n << " particle(s)." << endl;
// destruct all previous groups
for (auto i : groupList())
delete i;
// read groups
- fin >> n;
+ f >> n;
g.resize(n);
for (auto &i : groupList()) {
i = new Group();
- *i << fin;
+ *i << f;
i->setMassCenter(*this);
if ( i->name.empty() )
i->name = molecule[i->molId].name;
}
cout << indent(SUB) << "Read " << n << " group(s)." << endl;
}
string id;
- fin >> id;
+ f >> id;
if ( id=="randomstate" ) {
cout << indent(SUB) << "Restoring random number generator state." << endl;
- fin >> slump.eng;
+ f >> slump.eng;
}
initTracker(); // update trackers

0 comments on commit 732c204

Please sign in to comment.