00001 /* 00002 * RulePhrase.cpp 00003 * 00004 * Created on: 26 Feb 2014 00005 * Author: hieu 00006 */ 00007 00008 #include <sstream> 00009 #include "RulePhrase.h" 00010 #include "RuleSymbol.h" 00011 00012 using namespace std; 00013 00014 extern bool g_debug; 00015 00016 int RulePhrase::Compare(const RulePhrase &other) const 00017 { 00018 if (GetSize() != other.GetSize()) { 00019 return GetSize() < other.GetSize() ? -1 : +1; 00020 } 00021 00022 for (size_t i = 0; i < m_coll.size(); ++i) { 00023 const RuleSymbol &symbol = *m_coll[i]; 00024 const RuleSymbol &otherSymbol = *other.m_coll[i]; 00025 int compare = symbol.Compare(otherSymbol); 00026 00027 if (compare) { 00028 return compare; 00029 } 00030 } 00031 00032 return 0; 00033 } 00034 00035 void RulePhrase::Output(std::ostream &out) const 00036 { 00037 for (size_t i = 0; i < m_coll.size(); ++i) { 00038 const RuleSymbol &symbol = *m_coll[i]; 00039 symbol.Output(out); 00040 out << " "; 00041 } 00042 } 00043 00044 std::string RulePhrase::Debug() const 00045 { 00046 std::stringstream out; 00047 Output(out); 00048 return out.str(); 00049 } 00050