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