import source from 1.3.40
[external/swig.git] / Examples / octave / extend / example.h
1 /* File : example.h */
2
3 #include <cstdio>
4 #include <iostream>
5 #include <vector>
6 #include <string>
7 #include <cmath>
8
9 class Employee {
10 private:
11         std::string name;
12 public:
13         Employee(const char* n): name(n) {}
14         virtual std::string getTitle() { return getPosition() + " " + getName(); }
15         virtual std::string getName() { return name; }
16         virtual std::string getPosition() const { return "Employee"; }
17         virtual ~Employee() { printf("~Employee() @ %p\n", this); }
18 };
19
20
21 class Manager: public Employee {
22 public:
23         Manager(const char* n): Employee(n) {}
24         virtual std::string getPosition() const { return "Manager"; }
25 };
26
27
28 class EmployeeList {
29         std::vector<Employee*> list;
30 public:
31         EmployeeList() {
32                 list.push_back(new Employee("Bob"));
33                 list.push_back(new Employee("Jane"));
34                 list.push_back(new Manager("Ted"));
35         }
36         void addEmployee(Employee *p) {
37                 list.push_back(p);
38                 std::cout << "New employee added.   Current employees are:" << std::endl;
39                 std::vector<Employee*>::iterator i;
40                 for (i=list.begin(); i!=list.end(); i++) {
41                         std::cout << "  " << (*i)->getTitle() << std::endl;
42                 }
43         }
44         const Employee *get_item(int i) {
45                 return list[i];
46         }
47         ~EmployeeList() { 
48                 std::vector<Employee*>::iterator i;
49                 std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
50                 for (i=list.begin(); i!=list.end(); i++) {
51                         delete *i;
52                 }
53                 std::cout << "~EmployeeList empty." << std::endl;
54         }
55 };
56