PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/ruby/mark_function/example.cxx

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