triple.hpp

    1: #ifndef TRIPLE_HPP
    2: #define TRIPLE_HPP
    3: /*------------------------------------------------------------------------------
    4: 
    5:   Author:    Andy Rushton, from an original by Dan Milton
    6:   Copyright: (c) Southampton University 1999-2004
    7:              (c) Andy Rushton           2004-2009
    8:   License:   BSD License, see ../docs/license.html
    9: 
   10:   Similar to the STL pair but, guess what? It has three elements!
   11: 
   12:   ------------------------------------------------------------------------------*/
   13: 
   14: #include "os_fixes.hpp"
   15: #include "persistent.hpp"
   16: 
   17: ////////////////////////////////////////////////////////////////////////////////
   18: // the triple class
   19: 
   20: template<typename T1, typename T2, typename T3>
   21: struct triple
   22: {
   23:   typedef T1 first_type;
   24:   typedef T2 second_type;
   25:   typedef T3 third_type;
   26: 
   27:   T1 first;
   28:   T2 second;
   29:   T3 third;
   30: 
   31:   triple(void);
   32:   triple(const T1& p1, const T2& p2, const T3& p3);
   33:   triple(const triple<T1,T2,T3>& t2);
   34: };
   35: 
   36: ////////////////////////////////////////////////////////////////////////////////
   37: // creation
   38: 
   39: template<typename T1, typename T2, typename T3>
   40: triple<T1,T2,T3> make_triple(const T1& first, const T2& second, const T3& third);
   41: 
   42: ////////////////////////////////////////////////////////////////////////////////
   43: // comparison
   44: 
   45: template<typename T1, typename T2, typename T3>
   46: bool operator == (const triple<T1,T2,T3>& left, const triple<T1,T2,T3>& right);
   47: 
   48: template<typename T1, typename T2, typename T3>
   49: bool operator < (const triple<T1,T2,T3>& left, const triple<T1,T2,T3>& right);
   50: 
   51: ////////////////////////////////////////////////////////////////////////////////
   52: // string utilities
   53: 
   54: template<typename T1, typename T2, typename T3>
   55: std::string triple_to_string(const triple<T1,T2,T3>& values, const std::string& separator);
   56: 
   57: template<typename T1, typename T2, typename T3>
   58: otext& print_triple(otext& str, const triple<T1,T2,T3>& values, const std::string& separator);
   59: 
   60: template<typename T1, typename T2, typename T3>
   61: otext& print_triple(otext& str, const triple<T1,T2,T3>& values, const std::string& separator, unsigned indent);
   62: 
   63: ////////////////////////////////////////////////////////////////////////////////
   64: // data persistence
   65: 
   66: template<typename T1, typename T2, typename T3>
   67: void dump_triple(dump_context& str, const triple<T1,T2,T3>& data) throw(persistent_dump_failed);
   68: 
   69: template<typename T1, typename T2, typename T3>
   70: void restore_triple(restore_context& str, triple<T1,T2,T3>& data) throw(persistent_restore_failed);
   71: 
   72: ////////////////////////////////////////////////////////////////////////////////
   73: #include "triple.tpp"
   74: #endif