1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/multi_index/inc/employee.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +/* Used in Boost.MultiIndex tests.
1.5 + *
1.6 + * Copyright 2003-2006 Joaquín M López Muñoz.
1.7 + * Distributed under the Boost Software License, Version 1.0.
1.8 + * (See accompanying file LICENSE_1_0.txt or copy at
1.9 + * http://www.boost.org/LICENSE_1_0.txt)
1.10 + *
1.11 + * See http://www.boost.org/libs/multi_index for library home page.
1.12 + */
1.13 +
1.14 +#ifndef BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
1.15 +#define BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP
1.16 +
1.17 +#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
1.18 +#include <boost/mpl/vector.hpp>
1.19 +#include <boost/multi_index_container.hpp>
1.20 +#include <boost/multi_index/hashed_index.hpp>
1.21 +#include <boost/multi_index/identity.hpp>
1.22 +#include <boost/multi_index/member.hpp>
1.23 +#include <boost/multi_index/ordered_index.hpp>
1.24 +#include <boost/multi_index/random_access_index.hpp>
1.25 +#include <boost/multi_index/sequenced_index.hpp>
1.26 +#include <cstddef>
1.27 +#include <ostream>
1.28 +#include <string>
1.29 +
1.30 +struct employee
1.31 +{
1.32 + int id;
1.33 + std::string name;
1.34 + int age;
1.35 + int ssn;
1.36 +
1.37 + employee(int id_,std::string name_,int age_,int ssn_):
1.38 + id(id_),name(name_),age(age_),ssn(ssn_)
1.39 + {}
1.40 +
1.41 + bool operator==(const employee& x)const
1.42 + {
1.43 + return id==x.id&&name==x.name&&age==x.age;
1.44 + }
1.45 +
1.46 + bool operator<(const employee& x)const
1.47 + {
1.48 + return id<x.id;
1.49 + }
1.50 +
1.51 + bool operator!=(const employee& x)const{return !(*this==x);}
1.52 + bool operator> (const employee& x)const{return x<*this;}
1.53 + bool operator>=(const employee& x)const{return !(*this<x);}
1.54 + bool operator<=(const employee& x)const{return !(x<*this);}
1.55 +
1.56 + struct comp_id
1.57 + {
1.58 + bool operator()(int x,const employee& e2)const{return x<e2.id;}
1.59 + bool operator()(const employee& e1,int x)const{return e1.id<x;}
1.60 + };
1.61 +
1.62 + friend std::ostream& operator<<(std::ostream& os,const employee& e)
1.63 + {
1.64 + os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
1.65 + return os;
1.66 + }
1.67 +};
1.68 +
1.69 +struct name{};
1.70 +struct by_name{};
1.71 +struct age{};
1.72 +struct as_inserted{};
1.73 +struct ssn{};
1.74 +struct randomly{};
1.75 +
1.76 +struct employee_set_indices:
1.77 + boost::mpl::vector<
1.78 + boost::multi_index::ordered_unique<
1.79 + boost::multi_index::identity<employee> >,
1.80 + boost::multi_index::hashed_non_unique<
1.81 + boost::multi_index::tag<name,by_name>,
1.82 + BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>,
1.83 + boost::multi_index::ordered_non_unique<
1.84 + boost::multi_index::tag<age>,
1.85 + BOOST_MULTI_INDEX_MEMBER(employee,int,age)>,
1.86 + boost::multi_index::sequenced<
1.87 + boost::multi_index::tag<as_inserted> >,
1.88 + boost::multi_index::hashed_unique<
1.89 + boost::multi_index::tag<ssn>,
1.90 + BOOST_MULTI_INDEX_MEMBER(employee,int,ssn)>,
1.91 + boost::multi_index::random_access<
1.92 + boost::multi_index::tag<randomly> > >
1.93 +{};
1.94 +
1.95 +typedef
1.96 + boost::multi_index::multi_index_container<
1.97 + employee,
1.98 + employee_set_indices> employee_set;
1.99 +
1.100 +#if defined(BOOST_NO_MEMBER_TEMPLATES)
1.101 +typedef boost::multi_index::nth_index<
1.102 + employee_set,1>::type employee_set_by_name;
1.103 +#else
1.104 +typedef employee_set::nth_index<1>::type employee_set_by_name;
1.105 +#endif
1.106 +
1.107 +typedef boost::multi_index::index<
1.108 + employee_set,age>::type employee_set_by_age;
1.109 +typedef boost::multi_index::index<
1.110 + employee_set,as_inserted>::type employee_set_as_inserted;
1.111 +typedef boost::multi_index::index<
1.112 + employee_set,ssn>::type employee_set_by_ssn;
1.113 +
1.114 +#if defined(BOOST_NO_MEMBER_TEMPLATES)
1.115 +typedef boost::multi_index::index<
1.116 + employee_set,randomly>::type employee_set_randomly;
1.117 +#else
1.118 +typedef employee_set::index<
1.119 + randomly>::type employee_set_randomly;
1.120 +#endif
1.121 +
1.122 +#endif