From d43a0047151d490dcd061e3f105bfc4eb9fac854 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 2 Mar 2012 12:31:38 +0200 Subject: New example that shows C++11 support, build infrastructure for C++11 --- c++11/employee.hxx | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 c++11/employee.hxx (limited to 'c++11/employee.hxx') diff --git a/c++11/employee.hxx b/c++11/employee.hxx new file mode 100644 index 0000000..3750ca0 --- /dev/null +++ b/c++11/employee.hxx @@ -0,0 +1,182 @@ +// file : boost/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include // std::unique_ptr, std::shared_ptr +#include +#include + +#include +#include // odb::lazy_shared_ptr, odb::lazy_weak_ptr + +// Forward declarations. +// +class employer; +class employee; + +#pragma db object pointer(std::shared_ptr) +class employer +{ +public: + employer (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Employees of this employer. + // + typedef std::vector> employees_type; + + const employees_type& + employees () const + { + return employees_; + } + + employees_type& + employees () + { + return employees_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null inverse(employer_) + employees_type employees_; +}; + +#pragma db object pointer(std::shared_ptr) +class employee +{ +public: + typedef ::employer employer_type; + + employee (const std::string& first, + const std::string& last, + std::shared_ptr employer) + : first_ (first), last_ (last), employer_ (employer) + { + } + + // Name. + // + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Emails. + // + typedef std::unordered_set emails_type; + + const emails_type& + emails () const + { + return emails_; + } + + emails_type& + emails () + { + return emails_; + } + + // Employer. + // + std::shared_ptr + employer () const + { + return employer_; + } + + void + employer (std::shared_ptr employer) + { + employer_ = employer; + } + +private: + friend class odb::access; + + employee () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + emails_type emails_; + + #pragma db not_null + std::shared_ptr employer_; +}; + +// std::unique_ptr is a good choice for an object pointer if we are +// not planning to do any sharing. +// +#pragma db object pointer(std::unique_ptr) +class pension_fund +{ +public: + pension_fund (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Members of this fund. + // + typedef std::vector> members_type; + + const members_type& + members () const + { + return members_; + } + + members_type& + members () + { + return members_; + } + +private: + friend class odb::access; + + pension_fund () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null + members_type members_; +}; + +#endif // EMPLOYEE_HXX -- cgit v1.1