Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

Triple.cpp

00001 #define TRACE_NAME "Triple"
00002 #include "Triple.h"
00003 //   why do I have _size at all?  I don't remember what that might be for!
00004 
00006 //
00007 //  Standard Member Functions
00008 //
00010 
00011 const Triple Triple::null;
00012 
00013 Triple::Triple()
00014 {
00015     _size = 0;
00016 }
00017 
00018 Triple::Triple(const Triple& other)
00019 {
00020     for(size_t i=0; i<other.size(); i++) {
00021     data[i] = other.data[i];
00022     }
00023     _size = other.size();
00024 }
00025 
00026 const Triple& Triple::operator=(const Triple& other)
00027 {
00028     for(size_t i=0; i<other.size(); i++) {
00029     data[i] = other.data[i];
00030     }
00031     _size = other.size();
00032     return other;
00033 }
00034 
00035 bool Triple::operator==(const Triple& other) const
00036 {
00037     //std::cout << "Comparing " << *this << " and " << other << std::endl;
00038     // if (this == &other) return true;
00039     // if (_size != other._size) return false;
00040     for(size_t i=0; i<max_elements; i++) {
00041     if (data[i] != other.data[i]) return false;
00042     }
00043     // std::cout << " The SAME! " << std::endl;
00044     return true;
00045 }
00046 
00047 bool Triple::operator<(const Triple& other) const
00048 {
00049     NOT_IMPLEMENTED
00050 }
00051 
00052 size_t Triple::hash() const
00053 {
00054     size_t val = 0;
00055     for(size_t i=0; i<size(); i++) {
00056     val += (data[i].hash() << i);
00057     }
00058     return val;
00059 }
00060 
00061 std::ostream& Triple::print_to(std::ostream& stream) const
00062 {
00063     for(size_t i=0; i<size(); i++) {
00064     stream << data[i];
00065     if (i+1 < size()) stream << " ";
00066     }
00067     return stream;
00068 }
00069 
00070 Triple::~Triple()
00071 {
00072 }
00073 
00075 //
00076 //  Additional Public Member Functions
00077 //
00079 
00080 Triple::Triple(Symbol subject, Symbol predicate, Symbol object) 
00081 {
00082     _size = 3;
00083     data[0] = subject;
00084     data[1] = predicate;
00085     data[2] = object;
00086 }
00087 
00088 Symbol Triple::get(size_t index) const 
00089 {
00090     assert(index < max_elements);
00091     return data[index];
00092 }
00093 
00094 void Triple::set(size_t index, value_type symbol)
00095 {
00096     assert(index < max_elements);
00097     data[index] = symbol;
00098     if (index+1 > _size) _size = index+1;
00099 }
00100 
00101 void Triple::clear()
00102 {
00103     for(size_t i=0; i<size(); i++) {
00104     data[i] = Symbol();
00105     }
00106     _size = 0;
00107 }
00108 
00109 size_t Triple::size() const 
00110 {
00111     return _size;
00112 }
00113 
00115 //
00116 //  Additional Private Member Functions
00117 //
00119 
00120 #undef TRACE_NAME

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.