aboutsummaryrefslogtreecommitdiff
path: root/inheritance/polymorphism/employee.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-04-25 10:45:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-04-25 10:45:32 +0200
commitab994fdada3eebc794d6b1686f55a35420e4d758 (patch)
treeccfbdd212fc3a06fea8f68b07c01f68989d2e450 /inheritance/polymorphism/employee.hxx
parent27245519b1a659eb849a31714df0090dc58bb87a (diff)
New example, inheritance/polymorphism
Also move the inheritance example to inheritance/reuse.
Diffstat (limited to 'inheritance/polymorphism/employee.hxx')
-rw-r--r--inheritance/polymorphism/employee.hxx109
1 files changed, 109 insertions, 0 deletions
diff --git a/inheritance/polymorphism/employee.hxx b/inheritance/polymorphism/employee.hxx
new file mode 100644
index 0000000..efb2c1c
--- /dev/null
+++ b/inheritance/polymorphism/employee.hxx
@@ -0,0 +1,109 @@
+// file : inheritance/polymorphism/employee.hxx
+// copyright : not copyrighted - public domain
+
+#ifndef EMPLOYEE_HXX
+#define EMPLOYEE_HXX
+
+#include <string>
+
+#include <odb/core.hxx>
+
+#pragma db object polymorphic
+class person
+{
+public:
+ person (const std::string& first, const std::string& last)
+ : first_ (first), last_ (last)
+ {
+ }
+
+ const std::string&
+ first () const
+ {
+ return first_;
+ }
+
+ const std::string&
+ last () const
+ {
+ return last_;
+ }
+
+ virtual
+ ~person () = 0;
+
+ virtual void
+ print () = 0;
+
+protected:
+ friend class odb::access;
+ person () {}
+
+ #pragma db id auto
+ unsigned long id_;
+
+ std::string first_;
+ std::string last_;
+};
+
+#pragma db object
+class employee: public person
+{
+public:
+ employee (const std::string& first,
+ const std::string& last,
+ bool temporary)
+ : person (first, last), temporary_ (temporary)
+ {
+ }
+
+ bool
+ temporary () const
+ {
+ return temporary_;
+ }
+
+ void
+ temporary (bool t)
+ {
+ temporary_ = t;
+ }
+
+ virtual void
+ print ();
+
+private:
+ friend class odb::access;
+ employee () {}
+
+ bool temporary_;
+};
+
+#pragma db object
+class contractor: public person
+{
+public:
+ contractor (const std::string& first,
+ const std::string& last,
+ const std::string& email)
+ : person (first, last), email_ (email)
+ {
+ }
+
+ const std::string&
+ email () const
+ {
+ return email_;
+ }
+
+ virtual void
+ print ();
+
+private:
+ friend class odb::access;
+ contractor () {}
+
+ std::string email_;
+};
+
+#endif // EMPLOYEE_HXX