Yurttas/PL/OOL/Cplusplus/F/04/03/00/vector e.cpp

From ZCubes Wiki
Jump to navigation Jump to search
  1/*
  2   Copyright(C) 2002
  3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
  4
  5   Permission to use, copy, modify, and distribute this
  6   software and its documentation for EDUCATIONAL purposes
  7   and without fee is hereby granted provided that this
  8   copyright notice appears in all copies.
  9
 10   date   : June 1, 2002.
 11   author : Salih Yurttas.
 12
 13   vector_e.cpp
 14*/
 15
 16
 17#include "vector_e.h"
 18
 19template <class T>
 20vector_e<T>::
 21vector_e(const int a,
 22         const T b) : d(a,b) {
 23}
 24
 25template <class T>
 26vector_e<T>::
 27vector_e<T>(const vector_e<T>& a) : d(a.d) {
 28}
 29
 30template <class T>
 31vector_e<T>&
 32vector_e<T>::
 33operator=(const vector_e<T>& a) {
 34  if(this==&a) return *this;
 35
 36  d = a.d;
 37
 38  return *this;
 39}
 40
 41template <class T>
 42int
 43vector_e<T>::
 44get_size() const {
 45  return d.size();
 46}
 47
 48template <class T>
 49T
 50vector_e<T>::
 51get_element(const int a) const {
 52  if(a>=0&&a<d.size())
 53    return d[a];
 54  else     
 55    cerr << "Beyond scope" << endl;
 56}
 57
 58template <class T>
 59vector<T>
 60vector_e<T>::
 61get_element(const int a,
 62            const int b) const {
 63  vector<T> t;
 64
 65  if((a>=0&&a<d.size()) &&
 66     (b>=0&&b<d.size()))
 67    for(int i=a; i<=b; i++)
 68      t.push_back(d[i]);
 69
 70  return t;
 71}
 72
 73template <class T>
 74void
 75vector_e<T>::
 76set_element(const int a,
 77            const T b) {
 78  if(a>=0&&a<d.size())
 79    d[a]=b;
 80  else 
 81    cerr << "Beyond scope" << endl;
 82}
 83
 84template <class T>
 85T&
 86vector_e<T>::
 87operator[](const int a) {
 88  if(a>=0&&a<d.size())
 89    return d[a];
 90}
 91
 92template <class T>
 93ostream&
 94operator<<(ostream& os,
 95           const vector_e<T>& a) {
 96  int n = a.d.size();
 97
 98  for(int i=0; i<n; i++)
 99    os << a.d[i] << endl;
100  os << endl;
101
102  return os;
103}