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 "y2/SymbolEntry.h"
00022 #include "ycp/YCPCode.h"
00023 #include "ycp/YCPBoolean.h"
00024 #include "ycp/y2log.h"
00025
00031 class YCPCodeCompare : public std::binary_function <const YCPValue &, const YCPValue &, bool>
00032 {
00033 private:
00034 SymbolEntryPtr se1;
00035 SymbolEntryPtr se2;
00036 YCPCode order;
00037 public:
00038
00039 YCPCodeCompare (const YCPValue &asym1, const YCPValue &asym2,
00040 const YCPCode &aorder)
00041 : se1 (asym1->asEntry ()->entry ())
00042 , se2 (asym2->asEntry ()->entry ())
00043 , order (aorder)
00044 {
00045 }
00046
00047 result_type operator () (first_argument_type a,
00048 second_argument_type b)
00049 {
00050 se1->setValue (a);
00051 se2->setValue (b);
00052 YCPValue ret = order->evaluate ();
00053
00054 if (ret.isNull ())
00055 {
00056 ycp2error ("Bad sort order %s", order->toString ().c_str ());
00057 return false;
00058 }
00059
00060 if (!ret->isBoolean ())
00061 {
00062 ycp2error ("sort(): order %s evaluates to %s, which is not a boolean", order->toString ().c_str ()
00063 , ret->toString ().c_str ());
00064 return false;
00065 }
00066
00067 return ret->asBoolean ()->value ();
00068 }
00069 };
00070
00071 #endif