os/ossrv/stdcpp/tsrc/Boost_test/multi_index/inc/employee.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* Used in Boost.MultiIndex tests.
     2  *
     3  * Copyright 2003-2006 Joaquín M López Muñoz.
     4  * Distributed under the Boost Software License, Version 1.0.
     5  * (See accompanying file LICENSE_1_0.txt or copy at
     6  * http://www.boost.org/LICENSE_1_0.txt)
     7  *
     8  * See http://www.boost.org/libs/multi_index for library home page.
     9  */
    10 
    11 #ifndef BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
    12 #define BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
    13 
    14 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
    15 #include <boost/mpl/vector.hpp>
    16 #include <boost/multi_index_container.hpp>
    17 #include <boost/multi_index/hashed_index.hpp>
    18 #include <boost/multi_index/identity.hpp>
    19 #include <boost/multi_index/member.hpp>
    20 #include <boost/multi_index/ordered_index.hpp>
    21 #include <boost/multi_index/random_access_index.hpp>
    22 #include <boost/multi_index/sequenced_index.hpp>
    23 #include <cstddef>
    24 #include <ostream>
    25 #include <string>
    26 
    27 struct employee
    28 {
    29   int         id;
    30   std::string name;
    31   int         age;
    32   int         ssn;
    33 
    34   employee(int id_,std::string name_,int age_,int ssn_):
    35     id(id_),name(name_),age(age_),ssn(ssn_)
    36   {}
    37 
    38   bool operator==(const employee& x)const
    39   {
    40     return id==x.id&&name==x.name&&age==x.age;
    41   }
    42 
    43   bool operator<(const employee& x)const
    44   {
    45     return id<x.id;
    46   }
    47 
    48   bool operator!=(const employee& x)const{return !(*this==x);}
    49   bool operator> (const employee& x)const{return x<*this;}
    50   bool operator>=(const employee& x)const{return !(*this<x);}
    51   bool operator<=(const employee& x)const{return !(x<*this);}
    52 
    53   struct comp_id
    54   {
    55     bool operator()(int x,const employee& e2)const{return x<e2.id;}
    56     bool operator()(const employee& e1,int x)const{return e1.id<x;}
    57   };
    58 
    59   friend std::ostream& operator<<(std::ostream& os,const employee& e)
    60   {
    61     os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
    62     return os;
    63   }
    64 };
    65 
    66 struct name{};
    67 struct by_name{};
    68 struct age{};
    69 struct as_inserted{};
    70 struct ssn{};
    71 struct randomly{};
    72 
    73 struct employee_set_indices:
    74   boost::mpl::vector<
    75     boost::multi_index::ordered_unique<
    76       boost::multi_index::identity<employee> >,
    77     boost::multi_index::hashed_non_unique<
    78       boost::multi_index::tag<name,by_name>,
    79       BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>,
    80     boost::multi_index::ordered_non_unique<
    81       boost::multi_index::tag<age>,
    82       BOOST_MULTI_INDEX_MEMBER(employee,int,age)>,
    83     boost::multi_index::sequenced<
    84       boost::multi_index::tag<as_inserted> >,
    85     boost::multi_index::hashed_unique<
    86       boost::multi_index::tag<ssn>,
    87       BOOST_MULTI_INDEX_MEMBER(employee,int,ssn)>,
    88     boost::multi_index::random_access<
    89       boost::multi_index::tag<randomly> > >
    90 {};
    91 
    92 typedef
    93   boost::multi_index::multi_index_container<
    94     employee,
    95     employee_set_indices>                employee_set;
    96 
    97 #if defined(BOOST_NO_MEMBER_TEMPLATES)
    98 typedef boost::multi_index::nth_index<
    99   employee_set,1>::type                  employee_set_by_name;
   100 #else
   101 typedef employee_set::nth_index<1>::type employee_set_by_name;
   102 #endif
   103 
   104 typedef boost::multi_index::index<
   105          employee_set,age>::type         employee_set_by_age;
   106 typedef boost::multi_index::index<
   107          employee_set,as_inserted>::type employee_set_as_inserted;
   108 typedef boost::multi_index::index<
   109          employee_set,ssn>::type         employee_set_by_ssn;
   110 
   111 #if defined(BOOST_NO_MEMBER_TEMPLATES)
   112 typedef boost::multi_index::index<
   113          employee_set,randomly>::type    employee_set_randomly;
   114 #else
   115 typedef employee_set::index<
   116           randomly>::type                employee_set_randomly;
   117 #endif
   118 
   119 #endif