cgv
Loading...
Searching...
No Matches
bool_combiner.cxx
1#include <iostream>
2#include <cgv/signal/bool_combiner.h>
3#include "bool_signal.h"
4
5namespace cgv {
6 namespace signal {
7
8void connect(bool_signal<>& s, bool(*fp)())
9{
10 s.connect(bool_function_functor<0>(fp));
11}
12
13void disconnect(bool_signal<>& s, bool(*fp)())
14{
15 s.disconnect(bool_function_functor<0>(fp));
16}
17
19bool bool_combiner::combine_result(bool new_value, bool& value) const
20{
21 if (combine_with_and) {
22 value &= new_value;
23 return short_circuit && !value;
24 }
25 value |= new_value;
26 return short_circuit && value;
27}
28
30{
31 short_circuit = true;
32 combine_with_and = true;
33 set_options(opt);
34}
35
38{
39 return combine_with_and;
40}
41
42
44void bool_combiner::set_options(const char* opt)
45{
46 std::string s(opt);
47 for (int i=0; i<(int)s.size(); ++i) {
48 switch (s[i]) {
49 case '*' : short_circuit = true; break;
50 case '+' : short_circuit = false; break;
51 case '&' : combine_with_and = true; break;
52 case '|' : combine_with_and = false; break;
53 default: std::cerr << "unkown option character '" << s[i] << "' in constructor of cgv::signal::bool_combiner" << std::endl;
54 }
55 }
56}
57
60{
61 return combine_with_and;
62}
65{
66 return short_circuit;
67}
68
69 }
70}
bool combine_result(bool new_value, bool &value) const
base class for signals that combine the boolean result of the attached functors with boolean and/or o...
bool get_neutral_value() const
return the neutral bool value with which one can initialize the result variable
bool_combiner(const char *opt)
construct from option string.
void set_options(const char *opt)
set a different option string
bool is_evaluation_short_circuit() const
return whether to perform short-circuit evaluation
bool is_combination_with_and() const
return whether combination is done with the boolean and operation
the cgv namespace
Definition print.h:11