New example to test free_functions. Makes use of tracking objects functionality.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7522 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cdb81f3c5b
commit
de4629ac7a
6 changed files with 375 additions and 0 deletions
49
Examples/ruby/free_function/example.h
Normal file
49
Examples/ruby/free_function/example.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef _EXAMPLE_H_
|
||||
#define _EXAMPLE_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class Animal
|
||||
{
|
||||
protected:
|
||||
std::string name_;
|
||||
public:
|
||||
// Construct an animal with a name
|
||||
Animal(const char* name);
|
||||
|
||||
// Destruct an animal
|
||||
~Animal();
|
||||
|
||||
// Return the animal's name
|
||||
const char* get_name() const;
|
||||
};
|
||||
|
||||
class Zoo
|
||||
{
|
||||
private:
|
||||
typedef std::vector<Animal*> AnimalsType;
|
||||
typedef AnimalsType::iterator IterType;
|
||||
protected:
|
||||
AnimalsType animals;
|
||||
public:
|
||||
Zoo();
|
||||
~Zoo();
|
||||
|
||||
/* Create a new animal */
|
||||
static Animal* create_animal(const char* name);
|
||||
|
||||
/* Add a new animal to the zoo */
|
||||
void add_animal(Animal* animal);
|
||||
|
||||
/* Remove an animal from the zoo */
|
||||
Animal* remove_animal(size_t i);
|
||||
|
||||
/* Return the number of animals in the zoo */
|
||||
size_t get_num_animals() const;
|
||||
|
||||
/* Return a pointer to the ith animal */
|
||||
Animal* get_animal(size_t i) const;
|
||||
};
|
||||
|
||||
#endif /*_EXAMPLE_H_*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue