40 #ifndef INFACT_EXAMPLE_H_
41 #define INFACT_EXAMPLE_H_
58 virtual int year()
const = 0;
60 virtual int month()
const = 0;
62 virtual int day()
const = 0;
68 #define REGISTER_DATE(TYPE) \
69 REGISTER_NAMED(TYPE,TYPE,Date)
90 virtual int year()
const {
return year_; }
92 virtual int month()
const {
return month_; }
94 virtual int day()
const {
return day_; }
111 virtual const string &
name()
const = 0;
115 virtual shared_ptr<const Date>
birthday()
const = 0;
122 #define REGISTER_PERSON(TYPE) \
123 REGISTER_NAMED(TYPE,TYPE,Person)
144 virtual const string &
name()
const {
return name_; }
146 virtual const int cm_height()
const {
return cm_height_; }
148 virtual shared_ptr<const Date>
birthday()
const {
return birthday_; }
153 shared_ptr<Date> birthday_;
165 virtual const string &
name()
const = 0;
168 virtual int age()
const = 0;
175 #define REGISTER_ANIMAL(TYPE) \
176 REGISTER_NAMED(TYPE,TYPE,Animal)
195 virtual const string &
name()
const {
return name_; }
196 virtual int age()
const {
return age_; }
239 virtual const string &
name()
const {
return name_; }
245 const vector<int> &
counts() {
return counts_; }
266 virtual shared_ptr<Animal>
GetPet(
int i) = 0;
273 #define REGISTER_PET_OWNER(TYPE) \
274 REGISTER_NAMED(TYPE,TYPE,PetOwner)
288 initializers.
Add(
"pets", &pets_,
true);
297 virtual shared_ptr<Animal>
GetPet(
int i) {
302 vector<shared_ptr<Animal> > pets_;
virtual shared_ptr< const Date > birthday() const =0
Returns the birthday of this person.
virtual void RegisterInitializers(Initializers &initializers)
Registers a single required initializer.
virtual int age() const
Returns the age of this animal.
virtual int GetNumberOfPets()
Returns the number of pets owned by this pet owner.
virtual ~PersonImpl()
Destroys this person.
virtual ~PetOwner()
Destroys this pet owner.
DateImpl()
Constructs this instance.
virtual int age() const
Returns the age of this animal.
virtual const string & name() const
Returns the name of this animal.
Sheep()
Constructs a sheep.
#define INFACT_ADD_PARAM_(param)
A macro to make it easy to register a parameter for initialization inside a RegisterInitializers impl...
virtual int age() const =0
Returns the age of this animal.
virtual int month() const =0
Returns the month.
virtual ~HumanPetOwner()
Destroys a human pet owner.
HumanPetOwner()
Constructs a human pet owner.
virtual int GetNumberOfPets()=0
Returns the number of pets owned by this pet owner.
virtual int year() const
Returns the year.
virtual const string & name() const =0
Returns the name of this person.
PetOwner()
Constructs a generic pet owner.
A very simple class to represent an animal.
Animal()
Constructs a generic animal.
virtual void PostInit(const Environment *env, const string &init_str)
Grabs the variable named "age" from the Environment (set up by RegisterInitializers) and sets this sh...
An implementation of the Date interface that can be constructed by a Factory (because of the REGISTER...
virtual const int cm_height() const
Returns the height in centimeters of this person.
virtual shared_ptr< const Date > birthday() const
Returns the birthday of this person.
virtual int day() const
Returns the day.
Date()
Constructs this date.
virtual int day() const =0
Returns the day.
virtual int year() const =0
Returns the year.
An interface to represent a date.
A container for all the member initializers for a particular Factory-constructible instance...
PersonImpl()
Constructs this person.
virtual void RegisterInitializers(Initializers &initializers)
Registers one required and two optional initializers.
An interface representing a person.
Provides a generic dynamic object factory.
virtual void RegisterInitializers(Initializers &initializers)
Registers one required and two optional inititalizers.
virtual ~Animal()
Destroys this animal.
const vector< int > & counts()
Returns the counts of this sheep.
virtual ~DateImpl()
Destroys this instance.
An interface for an environment in which variables of various types are mapped to their values...
virtual ~Date()
Destroys this date.
virtual ~Person()
Destroys this abstract person.
virtual const string & name() const
Returns the name of this animal.
Person()
Constructs this abstract person.
virtual int month() const
Returns the month.
A class to represent a cow.
An interface simply to make it easier to implement Factory-constructible types by implementing both r...
virtual shared_ptr< Animal > GetPet(int i)
Gets the pet with the specified index owned by this pet owner.
virtual const string & name() const
Returns the name of this person.
A concrete implementation of the Person interface that can be constructed by a Factory (because of th...
virtual shared_ptr< Animal > GetPet(int i)=0
Gets the pet with the specified index owned by this pet owner.
#define INFACT_ADD_TEMPORARY(type, var)
A macro to make it easier to register a temporary variable inside a RegisterInitializers implementati...
void Add(const string &name, T *member, bool required=false)
This method is the raison d'etre of this class: a method to make it easy to add all supported types o...
virtual void RegisterInitializers(Initializers &initializers)
Registers three required initializers.
virtual void RegisterInitializers(Initializers &initializers)
Registers data members of this class for initialization when an instance is constructed via the Facto...
virtual const string & name() const =0
Returns the name of this animal.
virtual const int cm_height() const =0
Returns the height in centimeters of this person.
A concrete type of PetOwner that can be constructed by a Factory<PetOwner> instance.
#define INFACT_ADD_REQUIRED_PARAM_(param)
Identical to INFACT_ADD_PARAM_ but for a required parameter.
virtual ~Sheep()
Destroys a sheep.