1 /* 2 * RIntCntxt.cpp 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 #ifndef R_INTERNAL_CONTEXT_HPP 17 #define R_INTERNAL_CONTEXT_HPP 18 19 #include "RInterface.hpp" 20 #include "RCntxt.hpp" 21 22 namespace rstudio { 23 namespace r { 24 namespace context { 25 26 // header-only implementation of the RCntxtInterface; can serve as an 27 // implementation for any memory layout (depending on the template parameter) 28 template<typename T> class RIntCntxt: public RCntxtInterface 29 { 30 public: RIntCntxt(T * pCntxt)31 explicit RIntCntxt(T *pCntxt) : 32 pCntxt_(pCntxt) 33 { } 34 callfun() const35 SEXP callfun() const 36 { 37 return pCntxt_->callfun; 38 } 39 callflag() const40 int callflag() const 41 { 42 return pCntxt_->callflag; 43 } 44 evaldepth() const45 int evaldepth() const 46 { 47 return pCntxt_->evaldepth; 48 } 49 call() const50 SEXP call() const 51 { 52 return pCntxt_->call; 53 } 54 srcref() const55 SEXP srcref() const 56 { 57 return pCntxt_->srcref; 58 } 59 cloenv() const60 SEXP cloenv() const 61 { 62 return pCntxt_->cloenv; 63 } 64 nextcontext() const65 RCntxt nextcontext() const 66 { 67 if (pCntxt_->nextcontext == nullptr) 68 return RCntxt(); 69 else 70 return RCntxt(pCntxt_->nextcontext); 71 } 72 isNull() const73 bool isNull() const 74 { 75 return false; 76 } 77 rcntxt() const78 void* rcntxt() const 79 { 80 return static_cast<void *>(pCntxt_); 81 } 82 83 private: 84 const T *pCntxt_; 85 }; 86 87 } // namespace context 88 } // namespace r 89 } // namespace rstudio 90 91 #endif 92 93