LCOV - code coverage report
Current view: top level - tools - TypesafePtr.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 14 14 100.0 %
Date: 2024-10-18 13:59:31 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2018-2023 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 "TypesafePtr.h"
      23             : #include "core/PlumedMainInitializer.h"
      24             : 
      25             : #include <iostream>
      26             : 
      27             : namespace PLMD {
      28             : 
      29       20137 : TypesafePtr TypesafePtr::fromSafePtr(void* safe) {
      30             :   auto s=(plumed_safeptr_x*)safe;
      31       20137 :   return TypesafePtr(const_cast<void*>(s->ptr), s->nelem, s->shape, s->flags);
      32             : }
      33             : 
      34      996002 : TypesafePtr TypesafePtr::copy() const {
      35      996002 :   auto passbyvalue=((flags>>25)&0x7)==1;
      36      996002 :   if(passbyvalue) throw ExceptionTypeError()<<"PLUMED is trying to copy the pointer of an object passed by value";
      37      996002 :   auto forbidstore=flags&0x10000000;
      38      996004 :   if(forbidstore) throw ExceptionTypeError()<<"PLUMED is trying to copy the pointer of an object for which this was forbidden";
      39             :   TypesafePtr ret;
      40      996000 :   ret.ptr=ptr;
      41      996000 :   ret.flags=flags;
      42      996000 :   ret.nelem=nelem;
      43      996000 :   ret.shape=shape;
      44      996000 :   return ret;
      45             : }
      46             : 
      47          48 : std::string TypesafePtr::extra_msg() {
      48             :   const char *text = "\n"
      49             :                      "If you are sure your code is correct you can disable this check with export PLUMED_TYPESAFE_IGNORE=yes\n"
      50             :                      "In case this is necessary, please report an issue to developers of PLUMED and of the MD code\n"
      51             :                      "See also https://github.com/plumed/plumed2/pull/653";
      52          48 :   return std::string(text);
      53             : }
      54             : 
      55             : }
      56             : 
      57             : 

Generated by: LCOV version 1.16