Rcpp Version 0.9.10
DottedPair.cpp
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 //
00003 // DottedPair.cpp: Rcpp R/C++ interface class library -- dotted pair lists
00004 // base class of Language and Pairlist
00005 //
00006 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
00007 //
00008 // This file is part of Rcpp.
00009 //
00010 // Rcpp is free software: you can redistribute it and/or modify it
00011 // under the terms of the GNU General Public License as published by
00012 // the Free Software Foundation, either version 2 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // Rcpp is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00022 
00023 #include <Rcpp/DottedPair.h>
00024 
00025 namespace Rcpp {
00026 
00027     DottedPair::~DottedPair(){}
00028     DottedPair::DottedPair() : RObject(){}
00029         
00030     DottedPair& DottedPair::operator=(const DottedPair& other){
00031         setSEXP( other.asSexp() ) ;
00032         return *this ;
00033     }
00034         
00035     void DottedPair::remove( const size_t& index ) {
00036         if( static_cast<R_len_t>(index) >= Rf_length(m_sexp) ) throw index_out_of_bounds() ;
00037         if( index == 0 ){
00038             setSEXP( CDR( m_sexp) ) ;
00039         } else{
00040             SEXP x = m_sexp ;
00041             size_t i=1;
00042             while( i<index ){ x = CDR(x) ; i++; }
00043             SETCDR( x, CDDR(x) ) ;
00044         }
00045     }
00046         
00047     DottedPair::Proxy::Proxy( DottedPair& v, const size_t& index_ ) : node(){
00048         if( static_cast<R_len_t>(index_) >= v.length() ) throw index_out_of_bounds() ;
00049         SEXP x = v ; /* implicit conversion */
00050         size_t i = 0 ;
00051         while( i<index_) {
00052             x = CDR(x) ;
00053             ++i ;
00054         }
00055         node = x ;
00056     }
00057         
00058     DottedPair::Proxy& DottedPair::Proxy::operator=(const Proxy& rhs){
00059         SEXP y = rhs ; /* implicit conversion */
00060         SETCAR( node, y ) ;
00061         return *this ;
00062     }
00063         
00064     DottedPair::Proxy& DottedPair::Proxy::operator=(SEXP rhs){
00065         SETCAR( node, rhs) ;
00066         return *this ;
00067     }
00068         
00069     const DottedPair::Proxy DottedPair::operator[]( int i ) const {
00070         return Proxy( const_cast<DottedPair&>(*this), i) ;
00071     }
00072     DottedPair::Proxy DottedPair::operator[]( int i ) {
00073         return Proxy( *this, i );
00074     }
00075         
00076         
00077 } // namespace Rcpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines