/trunk/Examples/ruby/mark_function/example.cxx
C++ | 61 lines | 43 code | 11 blank | 7 comment | 0 complexity | 7d55adba551b88682d16c9b31d3503e9 MD5 | raw file
1#include "example.h" 2 3Animal::Animal(const char* name) : name_(name) 4{ 5} 6 7Animal::~Animal() 8{ 9 name_ = "Destroyed"; 10} 11 12/* Return the animal's name */ 13const char* Animal::get_name() const 14{ 15 return name_.c_str(); 16} 17 18Zoo::Zoo() 19{ 20} 21 22Zoo::~Zoo() 23{ 24 return; 25} 26 27/* Create a new animal. */ 28Animal* Zoo::create_animal(const char* name) 29{ 30 return new Animal(name); 31} 32 33/* Add a new animal to the zoo. */ 34void Zoo::add_animal(Animal* animal) 35{ 36 animals.push_back(animal); 37} 38 39Animal* Zoo::remove_animal(size_t i) 40{ 41 /* Note a production implementation should check 42 for out of range errors. */ 43 Animal* result = this->animals[i]; 44 IterType iter = this->animals.begin(); 45 std::advance(iter, i); 46 this->animals.erase(iter); 47 48 return result; 49} 50 51/* Return the number of animals in the zoo. */ 52size_t Zoo::get_num_animals() const 53{ 54 return animals.size(); 55} 56 57/* Return a pointer to the ith animal */ 58Animal* Zoo::get_animal(size_t i) const 59{ 60 return animals[i]; 61}