Michele De Stefano's C++ Utilities
indexing_example.cpp

A simple Python extension module that shows the mds_utils::python::support_random_access and the mds_utils::python::support_random_getset_access usage.

Author
Michele De Stefano
Date
21/05/2014
// indexing_example.cpp
//
// Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
//
// Distributed under the MIT License (See accompanying file LICENSE)
#include "indexing_example.hpp"
using namespace std;
Dummy_Container::Dummy_Container() : m_v(9) {
m_v[0] = 1.1;
m_v[1] = 2.1;
m_v[2] = 3.1;
m_v[3] = 4.1;
m_v[4] = 5.1;
m_v[5] = 6.1;
m_v[6] = 7.1;
m_v[7] = 8.1;
m_v[8] = 9.1;
}
size_t Dummy_Container::get_nel() const {
return m_v.size();
}
double Dummy_Container::get_el_at(size_t i) const {
if (i >= m_v.size()) throw out_of_range("Index out of range");
return m_v[i];
}
void Dummy_Container::set_el_at(size_t i,double val) {
if (i >= m_v.size()) throw out_of_range("Index out of range");
m_v[i] = val;
}