LCOV - code coverage report
Current view: top level - vesselbase - Vessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 53 65 81.5 %
Date: 2018-12-19 07:49:13 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2018 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #include "Vessel.h"
      23             : #include "ActionWithVessel.h"
      24             : #include "tools/Exception.h"
      25             : #include "tools/Communicator.h"
      26             : #include "tools/Log.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace vesselbase {
      30             : 
      31         841 : Keywords VesselOptions::emptyKeys;
      32             : 
      33         468 : VesselOptions::VesselOptions(const std::string& thisname, const std::string& thislab, const unsigned& nlab, const std::string& params, ActionWithVessel* aa ):
      34             :   myname(thisname),
      35             :   mylabel(thislab),
      36             :   numlab(nlab),
      37             :   action(aa),
      38             :   keywords(emptyKeys),
      39         468 :   parameters(params)
      40             : {
      41         468 : }
      42             : 
      43         354 : VesselOptions::VesselOptions(const VesselOptions& da, const Keywords& keys ):
      44             :   myname(da.myname),
      45             :   mylabel(da.mylabel),
      46             :   numlab(da.numlab),
      47             :   action(da.action),
      48             :   keywords(keys),
      49         354 :   parameters(da.parameters)
      50             : {
      51         354 : }
      52             : 
      53         354 : void Vessel::registerKeywords( Keywords& keys ) {
      54         354 :   plumed_assert( keys.size()==0 );
      55         354 :   keys.add("optional","LABEL","the label used to reference this particular quantity");
      56         354 : }
      57             : 
      58         650 : std::string Vessel::transformName( const std::string& name ) {
      59         650 :   std::string tlabel=name;
      60             :   // Convert to lower case
      61         650 :   std::transform( tlabel.begin(), tlabel.end(), tlabel.begin(), tolower );
      62             :   // Remove any underscore characters (as these are reserved)
      63         816 :   for(unsigned i=0;; ++i) {
      64         816 :     std::size_t num=tlabel.find_first_of("_");
      65         816 :     if( num==std::string::npos ) break;
      66         166 :     tlabel.erase( tlabel.begin() + num, tlabel.begin() + num + 1 );
      67         166 :   }
      68         650 :   return tlabel;
      69             : }
      70             : 
      71         468 : Vessel::Vessel( const VesselOptions& da ):
      72             :   myname(da.myname),
      73             :   numlab(da.numlab),
      74             :   action(da.action),
      75             :   line(Tools::getWords( da.parameters )),
      76             :   keywords(da.keywords),
      77             :   finished_read(false),
      78             :   comm(da.action->comm),
      79         468 :   log((da.action)->log)
      80             : {
      81         468 :   if( da.mylabel.length()>0) {
      82           0 :     mylabel=da.mylabel;
      83             :   } else {
      84         468 :     if( keywords.exists("LABEL") ) parse("LABEL",mylabel);
      85         468 :     if( mylabel.length()==0 && numlab>=0 ) {
      86         371 :       mylabel=transformName( myname ); std::string nn;
      87         371 :       if(numlab>0) { Tools::convert( numlab, nn ); mylabel =  mylabel + "-" + nn; }
      88             :     }
      89             :   }
      90         468 : }
      91             : 
      92          76 : std::string Vessel::getName() const {
      93          76 :   return myname;
      94             : }
      95             : 
      96        1012 : std::string Vessel::getLabel() const {
      97        1012 :   return mylabel;
      98             : }
      99             : 
     100         159 : std::string Vessel::getAllInput() {
     101         159 :   std::string fullstring;
     102         672 :   for(unsigned i=0; i<line.size(); ++i) {
     103         513 :     fullstring = fullstring + " " + line[i];
     104             :   }
     105         159 :   line.clear(); line.resize(0);
     106         159 :   return fullstring;
     107             : }
     108             : 
     109         102 : void Vessel::parseFlag(const std::string&key, bool & t) {
     110             :   // Check keyword has been registered
     111         102 :   plumed_massert(keywords.exists(key), "keyword " + key + " has not been registered");
     112             :   // Check keyword is a flag
     113         102 :   if(!keywords.style(key,"nohtml")) {
     114         102 :     plumed_massert(keywords.style(key,"flag"), "keyword " + key + " is not a flag");
     115             :   }
     116             : 
     117             :   // Read in the flag otherwise get the default value from the keywords object
     118         102 :   if(!Tools::parseFlag(line,key,t)) {
     119          87 :     if( keywords.style(key,"nohtml") ) {
     120           0 :       t=false;
     121          87 :     } else if ( !keywords.getLogicalDefault(key,t) ) {
     122           0 :       plumed_merror("there is a flag with no logical default in a vessel - weird");
     123             :     }
     124             :   }
     125         102 : }
     126             : 
     127         413 : void Vessel::checkRead() {
     128         413 :   if(!line.empty()) {
     129           0 :     std::string msg="cannot understand the following words from input : ";
     130           0 :     for(unsigned i=0; i<line.size(); i++) {
     131           0 :       if(i>0) msg = msg + ", ";
     132           0 :       msg = msg + line[i];
     133             :     }
     134           0 :     error(msg);
     135             :   }
     136         413 :   finished_read=true;
     137         413 :   std::string describe=description();
     138         413 :   if( describe.length()>0 ) log.printf("  %s\n", describe.c_str() );
     139         413 : }
     140             : 
     141           0 : void Vessel::error( const std::string& msg ) {
     142           0 :   action->log.printf("ERROR for keyword %s in action %s with label %s : %s \n \n",myname.c_str(), (action->getName()).c_str(), (action->getLabel()).c_str(), msg.c_str() );
     143           0 :   if(finished_read) keywords.print( log );
     144           0 :   plumed_merror("ERROR for keyword " + myname + " in action "  + action->getName() + " with label " + action->getLabel() + " : " + msg );
     145             : }
     146             : 
     147             : }
     148        2523 : }

Generated by: LCOV version 1.13