YCPCodeCompare.h

Go to the documentation of this file.
00001 /*-----------------------------------------------------------*- c++ -*-\
00002 |                                                                      |  
00003 |                      __   __    ____ _____ ____                      |  
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |  
00005 |                       \ V / _` \___ \ | |   __) |                    |  
00006 |                        | | (_| |___) || |  / __/                     |  
00007 |                        |_|\__,_|____/ |_| |_____|                    |  
00008 |                                                                      |  
00009 |                               core system                            | 
00010 |                                                    (C) SUSE LINUX AG |  
00011 \----------------------------------------------------------------------/ 
00012 
00013    File:       YCPCodeCompare.h
00014    Author:     Martin Vidner <mvidner@suse.cz>
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/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     // in fact symbol entries and ycode
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

Generated on Fri Jun 16 18:07:45 2006 for yast2-core by  doxygen 1.4.6