void robot_config_t::validate() { for(key_t::const_iterator iter=keys_m.begin();iter!=keys_m.end();++iter) keys_m[iter->first]=to_lower(iter->second); for(size_t ii=0;ii<keys_m["robot"].size();++ii) if(keys_m["robot"][ii]=='\\') keys_m["robot"][ii]='/'; if(to_bool(keys_m["sim"])) { keys_m["delay_ms"]="100"; keys_m["baudrate"]="0"; } if(to_bool(keys_m["local"])) keys_m["superstar"]="http://localhost:8081"; if(to_bool(keys_m["dev"])) keys_m["superstar"]="http://test.robotmoose.com"; // if(keys_m["superstar"].size()>0&&keys_m["superstar"][keys_m["superstar"].size()-1]!='/') // keys_m["superstar"]+='/'; size_t slashes=0; for(size_t ii=0;ii<keys_m["robot"].size();++ii) if(keys_m["robot"][ii]=='/') ++slashes; if(slashes!=2) throw std::runtime_error("Invalid robot name \""+keys_m["robot"]+"\" - should be in the format \"school/name\"."); }
dsimp_config::dsimp_config(vm_obj const & o) { m_md = to_transparency_mode(cfield(o, 0)); m_max_steps = force_to_unsigned(cfield(o, 1)); m_canonize_instances = to_bool(cfield(o, 2)); m_single_pass = to_bool(cfield(o, 3)); m_fail_if_unchanged = to_bool(cfield(o, 4)); m_eta = to_bool(cfield(o, 5)); m_zeta = to_bool(cfield(o, 6)); m_beta = to_bool(cfield(o, 7)); m_proj = to_bool(cfield(o, 8)); m_iota = to_bool(cfield(o, 9)); m_unfold_reducible = to_bool(cfield(o, 10)); m_memoize = to_bool(cfield(o, 11)); }
void read_guide_file(char* filename) { std::fstream file(filename, std::fstream::in); int num_guides = 0; for (int i = 0; i < NUM_SLOTS/3; i++) { std::vector<int> slot_vector; slots.push_back(slot_vector); } if (file.is_open()) { std::string line; while (getline(file, line)) { std::stringstream ss(line); std::string name, class_year, gender, major, ethnicity, state, public_school, athlete, study_abroad, num_tours, avail; std::getline(ss, name, ','); std::getline(ss, gender, ','); std::getline(ss, class_year, ','); std::getline(ss, major, ','); std::getline(ss, state, ','); std::getline(ss, ethnicity, ','); std::getline(ss, public_school, ','); std::getline(ss, athlete, ','); std::getline(ss, study_abroad, ','); std::getline(ss, num_tours, ','); std::getline(ss, avail, ','); Guide* guide = new Guide(name, std::atoi(class_year.c_str()), major, gender, state, ethnicity, to_bool(public_school), to_bool(athlete), to_bool(study_abroad), std::atoi(num_tours.c_str()), avail); DEBUG(std::cout << guide->name << guide->gender << guide->ethnicity << guide->class_year << guide->major << guide->state << guide->public_school << guide->athlete << guide->study_abroad << guide->num_tours << ": ";) for (int i = 0; i < 20; i++) { if (guide->times[i] == 1) { slots[i].push_back(num_guides); } DEBUG(std::cout << guide->times[i];) } DEBUG(std::cout << "<br>";)
/** * Returns boolean from the argument list. */ char saffire_getopt_bool(int idx) { if (idx > saffire_params_count) return 0; int ret = to_bool(saffire_params[idx]); if (ret == -1) { printf("Incorrect boolean value"); exit(1); } return ret; }
bool operator== (const variant& rhs) const { if (type() == TYPE_NULL || rhs.type() == TYPE_NULL || type() != rhs.type()) return false; switch (type()) { case TYPE_BOOL: return to_bool() == rhs.to_bool(); case TYPE_INT: return to_int() == rhs.to_int(); case TYPE_DOUBLE: return to_float() == rhs.to_float(); case TYPE_STRING: return to_string() == rhs.to_string(); default: throw_type_error(type()); return false; // just to pease the compiler } }
gint prv_g_object_set(GstElement *effect_element, gchar *prop) { gchar **split_str = g_strsplit(prop, ",", 3); if (split_str == NULL) { g_error("bad property syntax\n"); return -1; } else if (g_str_has_suffix(split_str[1], "int")) g_object_set(effect_element, split_str[0], atoi(split_str[2]), NULL); else if (g_str_has_prefix(split_str[1], "bool")) g_object_set(effect_element, split_str[0], to_bool(split_str[2]), NULL); g_strfreev(split_str); }
// __wsp_filter_points {{{ wsp_return_t __wsp_filter_points( wsp_point_t *base, wsp_archive_t *archive, int offset, uint32_t count, wsp_point_t *points, wsp_point_t *result, wsp_error_t *e ) { uint32_t spp = archive->spp; uint32_t counter = base->timestamp + (spp * offset); uint32_t i; for (i = 0; i < count; i++) { wsp_point_t p = points[i]; if (DEBUG) { DEBUG_PRINTF( "compare: %u, %u: %s", counter, p.timestamp, to_bool(counter == p.timestamp) ); } if (p.timestamp == counter) { result[i] = p; } else { wsp_point_t zero = { .timestamp = counter, .value = NAN }; result[i] = zero; } counter += spp; } return WSP_OK; } // __wsp_filter_points }}}
/* * A signature consists of a series of items: * "s" needs (any) string (including ints) * "l" needs (long) integer * "b" needs boolean (true, false, yes, no, 0, 1) * "|" all items behind are optional */ void saffire_parse_signature(int argc, char **argv, char *signature) { int argp, idx; int optional = 0; // Shift all remaining non-parsed arguments to the front of the arglist int open_slot = 0; while (argv[open_slot]) open_slot++; for (int i=open_slot+1; i<argc; i++) { // Set initial open spot if (argv[i] && open_slot < i) { argv[open_slot] = argv[i]; argv[i] = NULL; while (argv[open_slot]) open_slot++; } } // We can "shrink" the argument count, since there are no open slots in between. argc = open_slot; if (argc == 0 && strlen(signature) > 0 && signature[0] != '|') { printf("Not enough arguments found. use saffire help <command> for more information\n"); exit(1); } // Process each character in the signature for (argp=0,idx=0; idx!=strlen(signature); idx++, argp++) { // The argument pointer exceeds the number of arguments but we are still parsing mandatory arguments. if (argp > argc && ! optional) { printf("Not enough arguments found. use saffire help <command> for more information\n"); exit(1); } switch (signature[idx]) { case '|' : // Use the same argument for next signature char. argp--; // Set optional flag. Everything afterwards is optional optional = 1; break; case 's' : // Strings are "as-is" break; case 'b' : // Try and convert to boolean if (to_bool(argv[argp]) == -1) { printf("Found '%s', but expected a boolean value\n", argv[argp]); exit(1); } break; case 'l' : // Convert to long. string("0") should be ok too! if (! strcasecmp(argv[argp], "0") && ! atol(argv[argp])) { printf("Found '%s', but expected a numerical value\n", argv[argp]); exit(1); } break; default : printf("Incorrect signature command '%c' found.\n", signature[idx]); exit(1); } } // Not enough arguments! if (argc > argp) { printf("Too many arguments found. use saffire help <command> for more information\n"); exit(1); } // All parameters are shifted to the front, and checked for type. From now on, we can safely use them saffire_params = argv; saffire_params_count = argc; }
bool options::get_bool(name const & n, bool default_value) const { sexpr const & r = get_sexpr(n); return !is_nil(r) && is_bool(r) ? to_bool(r) != 0 : default_value; }
vm_obj options_get_bool(vm_obj const & o, vm_obj const & n, vm_obj const & v) { return mk_vm_bool(to_options(o).get_bool(to_name(n), to_bool(v))); }
bool ConfigIni::tf(const string prop, const bool def) { return this->props->count(prop) ? to_bool((*(this->props))[prop], def) : def; }
inline bool get_bool_data(std::string key, bool def = false) { return to_bool(data[key], def); }
int main(int argc, char** argv) { int rc = 0; try { // Initialize runtime TA::World& world = TA::initialize(argc, argv); // Get command line arguments if (argc < 5) { std::cout << "Mocks t2(i,a,j,b) * v(a,b,c,d) term in CC amplitude eqs" << std::endl << "Usage: " << argv[0] << " occ_size occ_nblocks uocc_size " "uocc_nblocks [repetitions] [use_complex]" << std::endl; return 0; } const long n_occ = atol(argv[1]); const long nblk_occ = atol(argv[2]); const long n_uocc = atol(argv[3]); const long nblk_uocc = atol(argv[4]); if (n_occ <= 0) { std::cerr << "Error: occ_size must be greater than zero.\n"; return 1; } if (nblk_occ <= 0) { std::cerr << "Error: occ_nblocks must be greater than zero.\n"; return 1; } if (n_uocc <= 0) { std::cerr << "Error: uocc_size must be greater than zero.\n"; return 1; } if (nblk_uocc <= 0) { std::cerr << "Error: uocc_nblocks must be greater than zero.\n"; return 1; } if((n_occ < nblk_occ) != 0ul) { std::cerr << "Error: occ_size must be greater than occ_nblocks.\n"; return 1; } if((n_uocc < nblk_uocc) != 0ul) { std::cerr << "Error: uocc_size must be greater than uocc_nblocks.\n"; return 1; } const long repeat = (argc >= 6 ? atol(argv[5]) : 5); if (repeat <= 0) { std::cerr << "Error: number of repetitions must be greater than zero.\n"; return 1; } const bool use_complex = (argc >= 7 ? to_bool(argv[6]) : false); if(world.rank() == 0) std::cout << "TiledArray: CC T2.V term test..." << "\nGit HASH: " << TILEDARRAY_REVISION << "\nNumber of nodes = " << world.size() << "\nocc size = " << n_occ << "\nocc nblocks = " << nblk_occ << "\nuocc size = " << n_uocc << "\nuocc nblocks = " << nblk_uocc << "\nComplex = " << (use_complex ? "true" : "false") << "\n"; // Construct TiledRange1's std::vector<unsigned int> tiling_occ = make_tiling(n_occ, nblk_occ); std::vector<unsigned int> tiling_uocc = make_tiling(n_uocc, nblk_uocc); auto trange_occ = TA::TiledRange1(tiling_occ.begin(), tiling_occ.end()); auto trange_uocc = TA::TiledRange1(tiling_uocc.begin(), tiling_uocc.end()); if (use_complex) cc_abcd<std::complex<double>>(world, trange_occ, trange_uocc, repeat); else cc_abcd<double>(world, trange_occ, trange_uocc, repeat); TA::finalize(); } catch(TA::Exception& e) { std::cerr << "!! TiledArray exception: " << e.what() << "\n"; rc = 1; } catch(madness::MadnessException& e) { std::cerr << "!! MADNESS exception: " << e.what() << "\n"; rc = 1; } catch(SafeMPI::Exception& e) { std::cerr << "!! SafeMPI exception: " << e.what() << "\n"; rc = 1; } catch(std::exception& e) { std::cerr << "!! std exception: " << e.what() << "\n"; rc = 1; } catch(...) { std::cerr << "!! exception: unknown exception\n"; rc = 1; } return rc; }
void Inventory::fromFile(std::string filename){ std::ifstream infile(filename); if (infile){ if(filename == "game.txt"){ while (infile){ if(infile){ std::string strInput; std::getline(infile, strInput); if(strInput.length()>0){ std::stringstream splitter(strInput); //std::string title,price,copies,condition,genre,rating,maker; std::string title,price,copies,condition,genre,rating,maker,preorder; getline(splitter,title,','); getline(splitter,price,','); getline(splitter,copies,','); getline(splitter,condition,','); getline(splitter,preorder,','); getline(splitter,genre,','); getline(splitter,rating,','); getline(splitter,maker,','); Game* g = new Game(stoi(copies), stof(price), title, genre,rating, to_bool(condition),maker, to_bool(preorder)); gameStock.add(g); // std::cout << "\nRead:\t" << g->toString() << "\n"; } } } } if(filename == "console.txt"){ while (infile){ if(infile){ std::string strInput; std::getline(infile, strInput); if(strInput.length()>0){ std::stringstream splitter(strInput); std::string title,price,copies,condition,edition,maker,warranty; getline(splitter,title,','); getline(splitter,price,','); getline(splitter,copies,','); getline(splitter,condition,','); getline(splitter,edition,','); getline(splitter,maker,','); getline(splitter,warranty,','); Console* c = new Console(stoi(copies), stof(price), title, edition,maker, stoi(warranty), to_bool(condition)); consoleStock.add(c); // std::cout << "\nRead:\t" << c->toString() << "\n"; } } } } if(filename == "accessory.txt"){ while (infile){ if(infile){ std::string strInput; std::getline(infile, strInput); if(strInput.length()>0){ std::stringstream splitter(strInput); std::string title,price,copies,condition,consoleTo,warranty; getline(splitter,title,','); getline(splitter,price,','); getline(splitter,copies,','); getline(splitter,condition,','); getline(splitter,consoleTo,','); getline(splitter,warranty,','); Accessory* a = new Accessory(stoi(copies), stof(price), title, consoleTo, to_bool(condition), stoi(warranty)); acessStock.add(a); // std::cout << "\nRead:\t" << a->toString() << "\n"; } } } } infile.close(); } else { std::cout << "Can't read from file. Inventory not loaded.\n"; } }
vm_obj options_set_bool(vm_obj const & o, vm_obj const & n, vm_obj const & v) { return to_obj(to_options(o).update(to_name(n), to_bool(v))); }
vm_obj tactic_to_expr_core(vm_obj const & relaxed, vm_obj const & qe, vm_obj const & _s) { tactic_state const & s = to_tactic_state(_s); optional<metavar_decl> g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); if (!g_elaborate) { return mk_tactic_exception("elaborator is not available", s); } metavar_context mctx = s.mctx(); try { environment env = s.env(); expr r = (*g_elaborate)(env, s.get_options(), mctx, g->get_context(), to_expr(qe), to_bool(relaxed)); r = mctx.instantiate_mvars(r); if (relaxed && has_expr_metavar(r)) { buffer<expr> new_goals; name_set found; for_each(r, [&](expr const & e, unsigned) { if (!has_expr_metavar(e)) return false; if (is_metavar_decl_ref(e) && !found.contains(mlocal_name(e))) { mctx.instantiate_mvars_at_type_of(e); new_goals.push_back(e); found.insert(mlocal_name(e)); } return true; }); list<expr> new_gs = cons(head(s.goals()), to_list(new_goals.begin(), new_goals.end(), tail(s.goals()))); return mk_tactic_success(to_obj(r), set_env_mctx_goals(s, env, mctx, new_gs)); } else { return mk_tactic_success(to_obj(r), set_env_mctx(s, env, mctx)); } } catch (exception & ex) { return mk_tactic_exception(ex, s); } }
static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t val_len) { if (netdev == NULL) { return -ENODEV; } cc2420_t *dev = (cc2420_t *)netdev; int ext = netdev_ieee802154_set(&dev->netdev, opt, val, val_len); switch (opt) { case NETOPT_ADDRESS: assert(val_len == 2); cc2420_set_addr_short(dev, val); return 2; case NETOPT_ADDRESS_LONG: assert(val_len == 8); cc2420_set_addr_long(dev, val); return 8; case NETOPT_NID: assert(val_len == sizeof(uint16_t)); cc2420_set_pan(dev, to_u16(val)); return sizeof(uint16_t); case NETOPT_CHANNEL: assert(val_len == sizeof(uint16_t)); return cc2420_set_chan(dev, to_u16(val)); case NETOPT_TX_POWER: assert(val_len == sizeof(int16_t)); cc2420_set_txpower(dev, to_i16(val)); return sizeof(int16_t); case NETOPT_STATE: assert(val_len == sizeof(netopt_state_t)); return cc2420_set_state(dev, *((netopt_state_t *)val)); case NETOPT_AUTOACK: return cc2420_set_option(dev, CC2420_OPT_AUTOACK, to_bool(val)); case NETOPT_CSMA: return cc2420_set_option(dev, CC2420_OPT_CSMA, to_bool(val)); case NETOPT_PRELOADING: return cc2420_set_option(dev, CC2420_OPT_PRELOADING, to_bool(val)); case NETOPT_PROMISCUOUSMODE: return cc2420_set_option(dev, CC2420_OPT_PROMISCUOUS, to_bool(val)); case NETOPT_RX_START_IRQ: return cc2420_set_option(dev, CC2420_OPT_TELL_RX_START, to_bool(val)); case NETOPT_RX_END_IRQ: return cc2420_set_option(dev, CC2420_OPT_TELL_RX_END, to_bool(val)); case NETOPT_TX_START_IRQ: return cc2420_set_option(dev, CC2420_OPT_TELL_TX_START, to_bool(val)); case NETOPT_TX_END_IRQ: return cc2420_set_option(dev, CC2420_OPT_TELL_TX_END, to_bool(val)); default: return ext; } return 0; }
/// \brief Dump the internal data of this class in a human readable form. /// @remarks This should only be used for debugging purposes. void Element::dump(std::ostream& os) const { // GNASH_REPORT_FUNCTION; os << astype_str[_type] << ": "; if (_name) { os << " property name is: \"" << _name << "\", "; } else { os << "(no name), "; } os << "data length is " << getDataSize() << std::endl; switch (_type) { case Element::NUMBER_AMF0: os << to_number() << std::endl; break; case Element::BOOLEAN_AMF0: os << (to_bool() ? "true" : "false") << std::endl; break; case Element::STRING_AMF0: os << "(" << getDataSize() << " bytes): "; if (getDataSize()) { os << "\t\"" << to_string() << "\""; } std::cerr << std::endl; break; case Element::OBJECT_AMF0: break; case Element::MOVIECLIP_AMF0: case Element::NULL_AMF0: case Element::UNDEFINED_AMF0: case Element::REFERENCE_AMF0: case Element::ECMA_ARRAY_AMF0: case Element::OBJECT_END_AMF0: case Element::STRICT_ARRAY_AMF0: case Element::DATE_AMF0: case Element::LONG_STRING_AMF0: case Element::UNSUPPORTED_AMF0: case Element::RECORD_SET_AMF0: case Element::XML_OBJECT_AMF0: case Element::TYPED_OBJECT_AMF0: std::cerr << std::endl; break; case Element::AMF3_DATA: if (getDataSize() != 0) { gnash::log_debug(_("FIXME: got AMF3 data!")); } // cerr << "AMF3 data is: 0x" << hexify(_data, _length, false) << endl; break; // case Element::VARIABLE: // case Element::FUNCTION: // os << "# of properties in object: " << properties.size() << endl; // for (size_t i=0; i< properties.size(); i++) { // properties[i]->dump(); // } // break; default: // log_unimpl("%s: type %d", __PRETTY_FUNCTION__, (int)_type); break; } if (_type != Element::BOOLEAN_AMF0) { if (_buffer) { _buffer->dump(); } } if (_properties.size() > 0) { std::vector<std::shared_ptr<Element> >::const_iterator ait; os << "# of Properties in object: " << _properties.size() << std::endl; for (ait = _properties.begin(); ait != _properties.end(); ++ait) { const std::shared_ptr<Element> el = (*(ait)); el->dump(os); } } }
//! @name Constructors/Destructor //@{ data() : parent_( 0 ) , node_ ( 0 ) {} data( const XERCES_CPP_NAMESPACE::DOMNode& parent, const XERCES_CPP_NAMESPACE::DOMNode& node ) : parent_( &parent ) , node_ ( &node ) {} //@} //! @name Operations //@{ void to( std::string& v ) const { XEUMEULEU_TRY if( node_ ) v = translate( get_data() ); XEUMEULEU_CATCH } void to( bool& v ) const { XEUMEULEU_TRY if( node_ ) v = to_bool( get_data() ); XEUMEULEU_CATCH } void to( short& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< short >( get_data() ); XEUMEULEU_CATCH } void to( int& v ) const { XEUMEULEU_TRY if( node_ ) v = to_int( get_data() ); XEUMEULEU_CATCH } void to( long& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< long >( get_data() ); XEUMEULEU_CATCH } void to( long long& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< long long >( get_data() ); XEUMEULEU_CATCH } void to( float& v ) const { XEUMEULEU_TRY if( node_ ) v = to_float( get_data() ); XEUMEULEU_CATCH } void to( double& v ) const { XEUMEULEU_TRY if( node_ ) v = to_double( get_data() ); XEUMEULEU_CATCH } void to( long double& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< long double >( get_data() ); XEUMEULEU_CATCH } void to( unsigned short& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< unsigned short >( get_data() ); XEUMEULEU_CATCH } void to( unsigned int& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< unsigned int >( get_data() ); XEUMEULEU_CATCH } void to( unsigned long& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< unsigned long >( get_data() ); XEUMEULEU_CATCH } void to( unsigned long long& v ) const { XEUMEULEU_TRY if( node_ ) v = convert< unsigned long long >( get_data() ); XEUMEULEU_CATCH } //@} private: //! @name Helpers