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