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-11 08:09:47 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       12501 : TypesafePtr TypesafePtr::fromSafePtr(void* safe) {
      30             :   auto s=(plumed_safeptr_x*)safe;
      31       12501 :   return TypesafePtr(const_cast<void*>(s->ptr), s->nelem, s->shape, s->flags);
      32             : }
      33             : 
      34      506687 : TypesafePtr TypesafePtr::copy() const {
      35      506687 :   auto passbyvalue=((flags>>25)&0x7)==1;
      36      506687 :   if(passbyvalue) throw ExceptionTypeError()<<"PLUMED is trying to copy the pointer of an object passed by value";
      37      506687 :   auto forbidstore=flags&0x10000000;
      38      506687 :   if(forbidstore) throw ExceptionTypeError()<<"PLUMED is trying to copy the pointer of an object for which this was forbidden";
      39             :   TypesafePtr ret;
      40      506687 :   ret.ptr=ptr;
      41      506687 :   ret.flags=flags;
      42      506687 :   ret.nelem=nelem;
      43      506687 :   ret.shape=shape;
      44      506687 :   return ret;
      45             : }
      46             : 
      47           8 : 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           8 :   return std::string(text);
      53             : }
      54             : 
      55             : }
      56             : 
      57             : 

Generated by: LCOV version 1.15