yast2-core

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/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     // in fact symbol entries and ycode
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

Generated on a sunny day for yast2-core by doxygen 1.7.3