00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef YCPCodeCompare_h
00019 #define YCPCodeCompare_h
00020
00021 #include "ycp/SymbolEntry.h"
00022 #include "ycp/YCPCode.h"
00023 #include "ycp/y2log.h"
00024
00030 class YCPCodeCompare : public std::binary_function <const YCPValue &, const YCPValue &, bool>
00031 {
00032 private:
00033 SymbolEntryPtr se1;
00034 SymbolEntryPtr se2;
00035 YCPCode order;
00036 public:
00037
00038 YCPCodeCompare (const YCPValue &asym1, const YCPValue &asym2,
00039 const YCPCode &aorder)
00040 : se1 (asym1->asEntry ()->entry ())
00041 , se2 (asym2->asEntry ()->entry ())
00042 , order (aorder)
00043 {
00044 }
00045
00046 result_type operator () (first_argument_type a,
00047 second_argument_type b)
00048 {
00049 se1->setValue (a);
00050 se2->setValue (b);
00051 YCPValue ret = order->evaluate ();
00052
00053 if (ret.isNull ())
00054 {
00055 ycp2error ("Bad sort order %s", order->toString ().c_str ());
00056 return false;
00057 }
00058
00059 if (!ret->isBoolean ())
00060 {
00061 ycp2error ("sort(): order %s evaluates to %s, which is not a boolean", order->toString ().c_str ()
00062 , ret->toString ().c_str ());
00063 return false;
00064 }
00065
00066 return ret->asBoolean ()->value ();
00067 }
00068 };
00069
00070 #endif