bool Term::boolPropOptional(std::string const& name, bool defaultValue) { caValue* value = term_get_property(this, name.c_str()); if (value == NULL) return defaultValue; else return as_bool(value); }
void assign(caValue* value, int handle) { test_assert(!as_bool(g_slots[handle])); set_bool(g_slots[handle], true); caValue userdata; set_int(&userdata, handle); handle_t::set(value, &handle_type, &userdata); }
int get_free_slot() { for (int i=0; i < numSlots; i++) if (!as_bool(g_slots[i])) return i; test_assert(false); return -1; }
bool block_is_evaluation_empty(Block* block) { Value* prop = block_get_property(block, s_EvaluationEmpty); if (prop == NULL) return false; return as_bool(prop); }
bool block_has_effects(Block* block) { Value* prop = block_get_property(block, s_HasEffects); if (prop == NULL) return false; return as_bool(prop); }
friend closure_value operator< (closure_value const &lhs, closure_value const &rhs) { bool cmp = false; switch (lhs.type) { case is_int: switch(rhs.type) { case is_bool: cmp = lhs.value.i < as_long(rhs); break; case is_int: cmp = lhs.value.i < rhs.value.i; break; case is_uint: cmp = lhs.value.ui < rhs.value.ui; break; } break; case is_uint: cmp = lhs.value.ui < as_ulong(rhs); break; case is_bool: cmp = as_bool(lhs) < as_bool(rhs); break; } return closure_value(cmp, (value_error)(lhs.valid | rhs.valid)); }
tree evaluate_and (tree t) { if (N(t)<2) return evaluate_error ("bad and"); for (int i=0; i<N(t); i++) { tree u= evaluate (t[i]); if (!is_bool (u)) return evaluate_error ("bad and"); if (!as_bool (u)) return as_string_bool (false); } return as_string_bool (true); }
friend closure_value operator! (closure_value const &rhs) { switch (rhs.type) { case is_int: return closure_value(!as_long(rhs), rhs.valid); case is_bool: return closure_value(!as_bool(rhs), rhs.valid); case is_uint: break; } return closure_value(!as_ulong(rhs), rhs.valid); }
void evaluate_unbounded_loop(caStack* stack) { Branch* contents = (Branch*) circa_caller_branch(stack); // Check for zero evaluations if (!as_bool(circa_input(stack, 0))) { return; } push_frame(stack, contents); }
void test_block_as_assertions_list(Block* block, std::string const& contextStr) { if (has_static_errors(block)) { std::cout << "Static error " << contextStr << ":" << std::endl; print_static_errors_formatted(block, std::cout); declare_current_test_failed(); return; } std::stringstream checkInvariantsOutput; if (!block_check_invariants_print_result(block, checkInvariantsOutput)) { std::cout << "Failed invariant " << contextStr << std::endl; std::cout << checkInvariantsOutput.str() << std::endl; declare_current_test_failed(); return; } Stack context; evaluate_block(&context, block); if (context.errorOccurred) { std::cout << "Runtime error " << contextStr << std::endl; print_error_stack(&context, std::cout); declare_current_test_failed(); return; } int boolean_statements_found = 0; for (int i=0; i < block->length(); i++) { Term* term = block->get(i); if (!is_statement(term)) continue; if (!is_bool(term_value(term))) continue; boolean_statements_found++; if (!as_bool(term_value(term))) { std::cout << "Assertion failed " << contextStr << std::endl; std::cout << "failed: " << get_term_source_text(term) << std::endl; declare_current_test_failed(); return; } } if (boolean_statements_found == 0) { std::cout << "No boolean statements found " << contextStr << std::endl; declare_current_test_failed(); return; } }
void rgl_bg(int* successptr, int* idata) { int success = RGL_FAIL; Device* device = deviceManager->getAnyDevice(); if (device) { bool sphere = as_bool( idata[0] ); int fogtype = idata[1]; success = as_success( device->add( new Background(currentMaterial, sphere, fogtype) ) ); } *successptr = success; }
bool edit_graphics_rep::over_graphics (SI x, SI y) { frame f= find_frame (); if (!is_nil (f)) { point lim1, lim2; find_limits (lim1, lim2); point p = adjust (f [point (x, y)]); // cout << type << " at " << p << " [" << lim1 << ", " << lim2 << "]\n"; if (N(lim1) == 2) if ((p[0]<lim1[0]) || (p[0]>lim2[0]) || (p[1]<lim1[1]) || (p[1]>lim2[1])) return as_bool (call ("graphics-busy?")); return true; } return false; }
bool Value::isSameValue(const Value& other) const { switch(m_storedAs) { case valueType_float: return as_float() == other.as_float(); case valueType_double: return as_double() == other.as_double(); case valueType_uint16: return as_uint16() == other.as_uint16(); case valueType_uint32: return as_uint32() == other.as_uint32(); case valueType_int16: return as_int16() == other.as_int16(); case valueType_int32: return as_int32() == other.as_int32(); case valueType_uint8: return as_uint8() == other.as_uint8(); case valueType_bool: return as_bool() == other.as_bool(); case valueType_string: return as_string() == other.as_string(); default: return false; } }
Keyframe::Keyframe(JSONNode node) { auto jt = node.find("t"); if (jt == node.end()) { Logger::log(ERR, "Keyframe has no assigned time. Defaulting to 0."); t = 0; } else { t = jt->as_int(); } auto v = node.find("val"); if (v == node.end()) { val = nullptr; } else { val = shared_ptr<LumiverseType>(LumiverseTypeUtils::loadFromJSON(*v)); } auto ucs = node.find("useCurrentState"); if (ucs == node.end()) { useCurrentState = false; } else { useCurrentState = ucs->as_bool(); } auto tid = node.find("timelineID"); if (tid == node.end()) { timelineID = ""; } else { timelineID = tid->as_string(); } auto to = node.find("timelineOffset"); if (to == node.end()) { timelineOffset = 0; } else { timelineOffset = to->as_int(); } }
void test_assert_function(Term* term, int line, const char* file) { if (term == NULL) { std::cout << "NULL term in " << file << ", line " << line << std::endl; declare_current_test_failed(); return; } if (has_static_error(term)) { std::cout << "Compile error on term " << global_id(term) << std::endl; print_static_error(term, std::cout); std::cout << std::endl; std::cout << "Occurred in " << file << ", line " << line << std::endl; declare_current_test_failed(); } if (is_bool(term_value(term)) && !as_bool(term_value(term))) { std::cout << "Assertion failed: " << get_term_source_text(term) << std::endl; std::cout << "Occurred in " << file << ", line " << line << std::endl; declare_current_test_failed(); } }
url get_from_server (url u) { if (!is_rooted_tmfs (u)) return url_none (); url res= get_cache (u); if (!is_none (res)) return res; string name= as_string (u); if (ends (name, "~") || ends (name, "#")) { if (!is_rooted_tmfs (name)) return url_none (); if (!as_bool (call ("tmfs-can-autosave?", unglue (u, 1)))) return url_none (); } string r= as_string (call ("tmfs-load", object (name))); if (r == "") return url_none (); url tmp= url_temp (); (void) save_string (tmp, r, true); //return set_cache (u, tmp); return tmp; // FIXME: certain files could be cached, but others not // for instance, files which are loaded in a delayed fashion // would always be cached as empty files, which is erroneous. }
string scheme_language_rep::get_color (tree t, int start, int end) { static string none= ""; if (start >= end) return none; string s= t->label; for (int i= max (0, start-1000); i <= start; i++) switch (s[i]) { case ';': if (i>1 && s[i-1] == '\\' && s[i-2] == '#') break; return decode_color ("scheme", encode_color ("comment")); case '\042': if (i>1 && s[i-1] == '\\' && s[i-2] == '#') break; i++; while (i <= start && s[i] != '\042') if (s[i] == '\\' && i < start) i += 2; else i++; if (i >= start) return decode_color ("scheme", encode_color ("constant_string")); break; } if (is_numeric (s[start])) return decode_color ("scheme", encode_color ("constant_number")); if (s[start] == '\042' || s[start] == '#') return decode_color ("scheme", encode_color ("constant_string")); if (s[start] == ':') return decode_color ("scheme", encode_color ("declare_category")); string r= s (start, end); if (!colored->contains (r)) { colored (r)= ""; if (as_bool (call ("defined?", symbol_object (tm_decode (r))))) colored (r)= decode_color ("scheme", encode_color ("variable_identifier")); } return colored[r]; }
closure_value &operator-= (closure_value const &rhs) { switch (type) { case is_int: switch(rhs.type) { case is_bool: { long result = value.i - as_long(rhs); if (rhs.value.i > 0L && result > value.i || rhs.value.i < 0L && result < value.i) { valid = error_integer_overflow; } else { value.i = result; } } break; case is_int: { long result = value.i - rhs.value.i; if (rhs.value.i > 0L && result > value.i || rhs.value.i < 0L && result < value.i) { valid = error_integer_overflow; } else { value.i = result; } } break; case is_uint: { unsigned long result = value.ui - rhs.value.ui; if (result > value.ui) { valid = error_integer_overflow; } else { value.ui = result; type = is_uint; } } break; } break; case is_uint: switch(rhs.type) { case is_bool: { unsigned long result = value.ui - as_ulong(rhs); if (result > value.ui) { valid = error_integer_overflow; } else { value.ui = result; } } break; case is_int: { unsigned long result = value.ui - rhs.value.i; if (rhs.value.i > 0L && result > value.ui || rhs.value.i < 0L && result < value.ui) { valid = error_integer_overflow; } else { value.ui = result; } } break; case is_uint: { unsigned long result = value.ui - rhs.value.ui; if (result > value.ui) { valid = error_integer_overflow; } else { value.ui = result; } } break; } break; case is_bool: value.i = value.b - as_bool(rhs); type = is_int; } valid = (value_error)(valid | rhs.valid); return *this; }
closure_value &operator%= (closure_value const &rhs) { switch (type) { case is_int: switch(rhs.type) { case is_bool: case is_int: if (as_long(rhs) != 0) { if (value.i == -value.i && -1 == rhs.value.i) { // LONG_MIN % -1 on two's complement valid = error_integer_overflow; } else { value.i %= as_long(rhs); } } else { valid = error_division_by_zero; // division by zero } break; case is_uint: if (rhs.value.ui != 0) { value.ui %= rhs.value.ui; type = is_uint; } else { valid = error_division_by_zero; // division by zero } break; } break; case is_uint: if (as_ulong(rhs) != 0) value.ui %= as_ulong(rhs); else valid = error_division_by_zero; // division by zero break; case is_bool: if (as_bool(rhs)) { switch(rhs.type) { case is_int: value.i = (value.b ? 1 : 0) % rhs.value.i; type = is_int; break; case is_uint: value.i = (value.b ? 1 : 0) % rhs.value.ui; type = is_int; break; case is_bool: break; } } else { valid = error_division_by_zero; // division by zero } } return *this; }
bool edit_main_rep::get_bool_property (string what) { return as_bool (props [what]); }
inline bool as_bool (tree t) { if (is_atomic (t)) return as_bool (t->label); else return false; }
bool TWin::is_visible() { return as_bool(IsWindowVisible(m_hwnd)); }
bool TDialog::was_successful() { if (modeless()) return as_bool(handle()); else return as_bool(m_ret); }
TEST_FIXTURE( VariableTypeBoolFixture, BoolConvertsCorrectlyToBool ) { CHECK( true == as_bool( v ) ); }
/** * @brief Configures the block: defines the capture interface, the possible hw-queues in use, etc. * @param n The configuration parameters */ virtual void _configure(const pugi::xml_node& n) { std::cout << __PRETTY_FUNCTION__ << std::endl; int offset = 0; int slots = 131072; int caplen = 1514; bool timestamp = false; pugi::xml_node queues = n.child("queues"); if(!queues) throw std::runtime_error("PFQSource:: no queues node"); m_device = std::string(queues.attribute("device").value()); if(m_device.length()==0) throw std::runtime_error("PFQSource::no device attribute "); auto clattr = queues.attribute("caplen"); auto offattr = queues.attribute("offset"); auto slotattr = queues.attribute("slots"); auto tsattr = queues.attribute("tstamp"); if (!clattr.empty()) caplen = clattr.as_int(); if (!offattr.empty()) offset = offattr.as_int(); if (!slotattr.empty()) slots = slotattr.as_int(); if (!tsattr.empty()) timestamp = tsattr.as_bool(); std::vector<unsigned int> vq; m_pfq.open(caplen, offset, slots); for (xml_node queue=queues.child("queue"); queue; queue=queue.next_sibling("queue")) vq.push_back(queue.attribute("number").as_uint()); if(!vq.empty()) { auto it = vq.begin(); auto it_e = vq.end(); for (;it!=it_e;++it) { m_pfq.add_device(m_device.c_str(),*it); } } else { blocklog("PFQSource: no queues specified, sniffing on device ", log_info); m_pfq.add_device(m_device.c_str(), net::pfq::any_queue); } std::cout << "PFQ: dev:" << m_device << " caplen:" << caplen << " tstamp:" << std::boolalpha << timestamp; std::cout << " queues:"; std::copy(vq.begin(), vq.end(), std::ostream_iterator<int>(std::cout, ",")); std::cout << std::endl; { std::lock_guard<std::mutex> lock(m_mutex); m_max_caplen = std::max(m_max_caplen, caplen); } net::payload::size_of(m_max_caplen); // the slice_allocator must be created once the dynamic_buffer (or net::payload) // is set to a given size. // #if defined(USE_SIMPLE_PACKET) || defined(USE_SLICED_PACKET) m_allocator.reset(new allocator_type); #endif m_pfq.caplen(caplen); m_pfq.toggle_time_stamp(timestamp); m_pfq.enable(); }
bool operator==(boolean other) const { return as_bool() == other.as_bool(); }
/** Get a value as bool to a corresponding key \param key key \returns value */ bool value_as_bool(const char *key) { return as_bool(key, value(key)); }
friend closure_value operator>= (closure_value const &lhs, closure_value const &rhs) { return closure_value(!as_bool(lhs < rhs), (value_error)(lhs.valid | rhs.valid)); }
/* retrieving environment variables */ inline bool get_bool (string var) { tree t= env [var]; if (is_compound (t)) return false; return as_bool (t->label); }
bool connection_declared (string name) { return as_bool (call ("connection-defined?", name)); }