/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * Please see the COPYING file or "Copyright notice" in builder.cpp for details. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * ParticleTypeCheckers.cpp * * Created on: Nov 28, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "ParticleTypeCheckers.hpp" #include #include "CodePatterns/Assert.hpp" #include "CodePatterns/Log.hpp" bool ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering( const FunctionModel::arguments_t &args, const SerializablePotential::ParticleTypes_t &types ) { // check size if (types.size() != types.size()) return false; // check step-wise each FunctionModel::arguments_t::const_iterator iter = args.begin(); SerializablePotential::ParticleTypes_t::const_iterator firstcheckiter = types.begin(); SerializablePotential::ParticleTypes_t::const_iterator secondcheckiter = types.begin(); ++secondcheckiter; for(; iter != args.end(); ++iter){ if ((iter->types.first != *firstcheckiter) && (iter->types.second != *secondcheckiter)) { ELOG(1, iter->types.first << "," << iter->types.second << " does not match with " << *firstcheckiter << "," << *secondcheckiter << "."); return false; } ++secondcheckiter; if (secondcheckiter == types.end()) { ++firstcheckiter; ASSERT( firstcheckiter != types.end(), "checkArgumentsAgainstParticleTypesStrictOrdering() - not enough types?"); secondcheckiter = firstcheckiter+1; } } return true; } bool ParticleTypeChecker::checkArgumentsAgainstParticleTypes( const FunctionModel::arguments_t &args, const SerializablePotential::ParticleTypes_t &types ) { // check size if (types.size() != types.size()) return false; // check step-wise each bool status = true; for(FunctionModel::arguments_t::const_iterator iter = args.begin(); iter != args.end(); ++iter) { const SerializablePotential::ParticleTypes_t::const_iterator firstcheckiter = std::find( types.begin(), types.end(), iter->types.first ); const SerializablePotential::ParticleTypes_t::const_iterator secondcheckiter = std::find( types.begin(), types.end(), iter->types.second ); status &= (firstcheckiter != types.end()) && (secondcheckiter != types.end()); if (!status) break; } return status; }