Go to the documentation of this file.00001 #ifndef mmn_triplet_h_
00002 #define mmn_triplet_h_
00003
00004
00005
00006
00007
00008
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vcl_iostream.h>
00011 #include <vcl_vector.h>
00012
00013
00014
00015 class mmn_triplet
00016 {
00017 public:
00018 unsigned v1,v2,v3;
00019
00020 mmn_triplet() :v1(999999),v2(999999),v3(999999) {}
00021 mmn_triplet(unsigned i1, unsigned i2, unsigned i3)
00022 : v1(i1),v2(i2),v3(i3) {}
00023
00024
00025 unsigned min_v() const
00026 {
00027 if (v1<v2) return v1<v3?v1:v3;
00028 else return v2<v3?v2:v3;
00029 }
00030
00031
00032 unsigned mid_v() const
00033 {
00034 if (v1<v2)
00035 {
00036 if (v2<v3) return v2;
00037 else return v3<v1?v1:v3;
00038 }
00039 if (v1<v3) return v1;
00040 else return v3<v2?v2:v3;
00041 }
00042
00043
00044 unsigned max_v() const
00045 {
00046 if (v1>v2) return v1>v3?v1:v3;
00047 else return v2>v3?v2:v3;
00048 }
00049 };
00050
00051 inline bool operator==(const mmn_triplet& t1, const mmn_triplet& t2)
00052 {
00053 if (t1.v1==t2.v1)
00054 {
00055 if (t1.v2==t2.v2) return t1.v3==t2.v3;
00056 if (t1.v2==t2.v3) return t1.v3==t2.v2;
00057 return false;
00058 }
00059 if (t1.v1==t2.v2)
00060 {
00061 if (t1.v2==t2.v1) return t1.v3==t2.v3;
00062 if (t1.v2==t2.v3) return t1.v3==t2.v1;
00063 return false;
00064 }
00065 if (t1.v1==t2.v3)
00066 {
00067 if (t1.v2==t2.v1) return t1.v3==t2.v2;
00068 if (t1.v2==t2.v2) return t1.v3==t2.v1;
00069 return false;
00070 }
00071 return false;
00072 }
00073
00074 inline bool operator!=(const mmn_triplet& t1, const mmn_triplet& t2)
00075 { return !(t1==t2); }
00076
00077 inline vcl_ostream& operator<<(vcl_ostream& os, const mmn_triplet& t)
00078 {
00079 return os<<'{'<<t.v1<<','<<t.v2<<','<<t.v3<<'}';
00080 }
00081
00082 inline void vsl_b_write(vsl_b_ostream& bfs, const mmn_triplet& t)
00083 {
00084 vsl_b_write(bfs,t.v1);
00085 vsl_b_write(bfs,t.v2);
00086 vsl_b_write(bfs,t.v3);
00087 }
00088
00089 inline void vsl_b_read(vsl_b_istream& bfs, mmn_triplet& t)
00090 {
00091 vsl_b_read(bfs,t.v1);
00092 vsl_b_read(bfs,t.v2);
00093 vsl_b_read(bfs,t.v3);
00094 }
00095
00096 inline void vsl_b_write(vsl_b_ostream& bfs, const vcl_vector<mmn_triplet>& a)
00097 {
00098 short version_no = 1;
00099 vsl_b_write(bfs,version_no);
00100 vsl_b_write(bfs,a.size());
00101 for (unsigned i=0;i<a.size();++i) vsl_b_write(bfs,a[i]);
00102 }
00103
00104 inline void vsl_b_read(vsl_b_istream& bfs, vcl_vector<mmn_triplet>& a)
00105 {
00106 if (!bfs) return;
00107 short version;
00108 vsl_b_read(bfs,version);
00109 unsigned n;
00110 switch (version)
00111 {
00112 case (1):
00113 vsl_b_read(bfs,n);
00114 a.resize(n);
00115 for (unsigned i=0;i<n;++i) vsl_b_read(bfs,a[i]);
00116 break;
00117 default:
00118 vcl_cerr << "I/O ERROR: vsl_b_read(bfs,vector<mmn_triplet>)\n"
00119 << " Unknown version number "<< version << '\n';
00120 bfs.is().clear(vcl_ios::badbit);
00121 return;
00122 }
00123 }
00124
00125
00126 #endif // mmn_triplet_h_