yast2-core
YCPCodeCompare.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------*- c++ -*-\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SUSE LINUX AG |
11 \----------------------------------------------------------------------/
12 
13  File: YCPCodeCompare.h
14  Author: Martin Vidner <mvidner@suse.cz>
15 
16 /-*/
17 
18 #ifndef YCPCodeCompare_h
19 #define YCPCodeCompare_h
20 
21 #include "y2/SymbolEntry.h"
22 #include "ycp/YCPCode.h"
23 #include "ycp/YCPBoolean.h"
24 #include "ycp/y2log.h"
25 
31 class YCPCodeCompare : public std::binary_function <const YCPValue &, const YCPValue &, bool>
32 {
33 private:
34  SymbolEntryPtr se1;
35  SymbolEntryPtr se2;
37 public:
38  // in fact symbol entries and ycode
39  YCPCodeCompare (const YCPValue &asym1, const YCPValue &asym2,
40  const YCPCode &aorder)
41  : se1 (asym1->asEntry ()->entry ())
42  , se2 (asym2->asEntry ()->entry ())
43  , order (aorder)
44  {
45  }
46 
47  result_type operator () (first_argument_type a,
48  second_argument_type b)
49  {
50  se1->setValue (a);
51  se2->setValue (b);
52  YCPValue ret = order->evaluate ();
53 
54  if (ret.isNull ())
55  {
56  ycp2error ("Bad sort order %s", order->toString ().c_str ());
57  return false; // ???
58  }
59 
60  if (!ret->isBoolean ())
61  {
62  ycp2error ("sort(): order %s evaluates to %s, which is not a boolean", order->toString ().c_str ()
63  , ret->toString ().c_str ());
64  return false; // ???
65  }
66 
67  return ret->asBoolean ()->value ();
68  }
69 };
70 
71 #endif
SymbolEntryPtr se1
Definition: YCPCodeCompare.h:34
Definition: YCPCodeCompare.h:31
YCPCode order
Definition: YCPCodeCompare.h:36
#define ycp2error(format, args...)
Definition: libycp/src/include/ycp/y2log.h:41
SymbolEntryPtr se2
Definition: YCPCodeCompare.h:35
Wrapper for YCPCodeRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPCodeRep with the arrow operator. See YCPCodeRep.
Definition: YCPCode.h:96
bool isNull() const
Definition: YCPElement.h:347
Wrapper for YCPValueRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPValueRep with the arrow operator. See YCPValueRep.
Definition: YCPValue.h:275
result_type operator()(first_argument_type a, second_argument_type b)
Definition: YCPCodeCompare.h:47
YCPCodeCompare(const YCPValue &asym1, const YCPValue &asym2, const YCPCode &aorder)
Definition: YCPCodeCompare.h:39

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