/** Player selection. This command is compatible with the GoGui analyze command type "param". Parameters: @arg @c player Player id as in FuegoTestEngine::SetPlayer */ void FuegoTestEngine::CmdParam(GtpCommand& cmd) { cmd.CheckNuArgLessEqual(2); if (cmd.NuArg() == 0) { cmd << "[list/<none>/average/capture/dumbtactic/greedy/influence/" "ladder/liberty/maxeye/minlib/no-search/random/safe] player " << (m_playerId == "" ? "<none>" : m_playerId) << '\n'; } else if (cmd.NuArg() >= 1 && cmd.NuArg() <= 2) { string name = cmd.Arg(0); if (name == "player") { try { string id = trim_copy(cmd.RemainingLine(0)); if (id == "<none>") id = ""; SetPlayer(id); } catch (const SgException& e) { throw GtpFailure(e.what()); } } else throw GtpFailure() << "unknown parameter: " << name; } else throw GtpFailure() << "need 0 or 2 arguments"; }
bool NastranTokenizer::isNextEmpty() { if (nextSymbolType != NastranTokenizer::SYMBOL_FIELD) { return false; } string curField = trim_copy(currentLineVector[currentField]); return curField.empty(); }
double NastranTokenizer::nextDouble(bool returnDefaultIfNotFoundOrBlank, double defaultValue) { double result; if (returnDefaultIfNotFoundOrBlank && this->nextSymbolType != SYMBOL_FIELD) { return defaultValue; } string value = trim_copy(nextSymbolString()); if (returnDefaultIfNotFoundOrBlank && value.empty()) { return defaultValue; } boost::replace_all(value, "d", "e"); boost::replace_all(value, "D", "E"); boost::algorithm::erase_all(value, " "); size_t position = value.find_first_of("+-", 1); if (position != string::npos and position != value.find_first_of("eE", 1) + 1) { value.insert(position, "E"); } try { result = lexical_cast<double>(value); } catch (boost::bad_lexical_cast &e) { string currentFieldstr = currentField == 0 ? string("LAST") : (lexical_cast<string>(currentField - 1)); string message = "Value: [" + value + "]can't be converted to double. Field Num: " + currentFieldstr + " " + e.what(); throw vega::ParsingException(message, fileName, lineNumber); } return result; }
bool NastranTokenizer::isNextInt() { if (nextSymbolType != NastranTokenizer::SYMBOL_FIELD) { return false; } string curField = trim_copy(currentLineVector[currentField]); return !curField.empty() && (strspn(curField.c_str(), "-0123456789") == curField.size()); }
void NastranTokenizer::splitFreeFormat(string line, bool firstLine) { if (firstLine) { split(currentLineVector, line, boost::is_any_of(",")); } else { //skip first field; string lineNoContinuation = line.substr(line.find(',') + 1); vector<string> otherLine; split(otherLine, lineNoContinuation, boost::is_any_of(",")); currentLineVector.insert(currentLineVector.end(), otherLine.begin(), otherLine.end()); } bool explicitContinuation = false; for (size_t fieldIndex = 1; fieldIndex < currentLineVector.size(); fieldIndex += 8) { string field = trim_copy(currentLineVector[fieldIndex]); if (field[0] == '+') { explicitContinuation = true; currentLineVector.erase(currentLineVector.begin() + fieldIndex); } } char c = static_cast<char>(this->instrream.peek()); string line2; if (explicitContinuation || c == ',' || c == '+' || c == '*') { readLineSkipComment(line2); splitFreeFormat(line2, false); } }
bool NastranTokenizer::isNextDouble() { if (nextSymbolType != NastranTokenizer::SYMBOL_FIELD) { return false; } string curField = trim_copy(currentLineVector[currentField]); boost::algorithm::erase_all(curField, " "); return !curField.empty() && (strspn(curField.c_str(), "-+0123456789.eEdD") == curField.size()); }
string NastranTokenizer::nextString(bool returnDefaultIfNotFoundOrBlank, string defaultValue) { string result; if (returnDefaultIfNotFoundOrBlank && (this->nextSymbolType != SYMBOL_FIELD)) { return defaultValue; } string value = nextSymbolString(); if (returnDefaultIfNotFoundOrBlank && !defaultValue.empty() && trim_copy(value).empty()) { value = defaultValue; } return value; }
bool NastranTokenizer::isEmptyUntilNextKeyword() { if (nextSymbolType == NastranTokenizer::SYMBOL_KEYWORD) { return true; } else if (nextSymbolType == NastranTokenizer::SYMBOL_EOF) { return true; } bool result = true; for (size_t i = currentField; i < this->currentLineVector.size() && result; i++) { string curField = trim_copy(currentLineVector[i]); result &= curField.empty(); } return result; }
int NastranTokenizer::nextInt(bool returnDefaultIfNotFoundOrBlank, int defaultValue) { int result; if (returnDefaultIfNotFoundOrBlank && this->nextSymbolType != SYMBOL_FIELD) { return defaultValue; } string value = trim_copy(nextSymbolString()); if (returnDefaultIfNotFoundOrBlank && value.empty()) { return defaultValue; } try { result = lexical_cast<int>(value); } catch (boost::bad_lexical_cast &) { string currentFieldstr = currentField == 0 ? string("LAST") : (lexical_cast<string>(currentField - 1)); string message = "Value: [" + value + "] can't be converted to int. Field Num:" + currentFieldstr; throw vega::ParsingException(message, fileName, lineNumber); } return result; }
feature_ptr postgis_featureset::next() { if (rs_->next()) { // new feature unsigned pos = 1; feature_ptr feature; if (key_field_) { // create feature with user driven id from attribute int oid = rs_->getTypeOID(pos); const char* buf = rs_->getValue(pos); std::string name = rs_->getFieldName(pos); // validation happens of this type at bind() int val; if (oid == 20) { val = int8net(buf); } else if (oid == 21) { val = int2net(buf); } else { val = int4net(buf); } feature = feature_factory::create(ctx_, val); // TODO - extend feature class to know // that its id is also an attribute to avoid // this duplication feature->put(name,val); ++pos; } else { // fallback to auto-incrementing id feature = feature_factory::create(ctx_, feature_id_); ++feature_id_; } // parse geometry int size = rs_->getFieldLength(0); const char *data = rs_->getValue(0); geometry_utils::from_wkb(feature->paths(), data, size); totalGeomSize_ += size; int num_attrs = ctx_->size() + 1; for (; pos < num_attrs; ++pos) { std::string name = rs_->getFieldName(pos); if (rs_->isNull(pos)) { feature->put(name, mapnik::value_null()); } else { const char* buf = rs_->getValue(pos); const int oid = rs_->getTypeOID(pos); switch (oid) { case 16: //bool { feature->put(name, (buf[0] != 0)); break; } case 23: //int4 { int val = int4net(buf); feature->put(name, val); break; } case 21: //int2 { int val = int2net(buf); feature->put(name, val); break; } case 20: //int8/BigInt { int val = int8net(buf); feature->put(name, val); break; } case 700: //float4 { float val; float4net(val, buf); feature->put(name, val); break; } case 701: //float8 { double val; float8net(val, buf); feature->put(name, val); break; } case 25: //text case 1043: //varchar { feature->put(name, tr_->transcode(buf)); break; } case 1042: //bpchar { feature->put(name, tr_->transcode(trim_copy(std::string(buf)).c_str())); break; } case 1700: //numeric { double val; std::string str = mapnik::sql_utils::numeric2string(buf); if (mapnik::util::string2double(str, val)) { feature->put(name, val); } break; } default: { #ifdef MAPNIK_DEBUG std::clog << "Postgis Plugin: uknown OID = " << oid << std::endl; #endif break; } } } } return feature; } else { rs_->close(); return feature_ptr(); } }
feature_ptr postgis_featureset::next() { if (rs_->next()) { // new feature feature_ptr feature; unsigned pos = 1; if (key_field_) { // create feature with user driven id from attribute int oid = rs_->getTypeOID(pos); const char* buf = rs_->getValue(pos); std::string name = rs_->getFieldName(pos); // validation happens of this type at bind() int val; if (oid == 20) { val = int8net(buf); } else if (oid == 21) { val = int2net(buf); } else { val = int4net(buf); } feature = feature_factory::create(val); // TODO - extend feature class to know // that its id is also an attribute to avoid // this duplication boost::put(*feature,name,val); ++pos; } else { // fallback to auto-incrementing id feature = feature_factory::create(feature_id_); ++feature_id_; } // parse geometry int size = rs_->getFieldLength(0); const char *data = rs_->getValue(0); geometry_utils::from_wkb(feature->paths(),data,size,multiple_geometries_); totalGeomSize_+=size; for ( ;pos<num_attrs_+1;++pos) { std::string name = rs_->getFieldName(pos); if (rs_->isNull(pos)) { boost::put(*feature,name,mapnik::value_null()); } else { const char* buf = rs_->getValue(pos); int oid = rs_->getTypeOID(pos); if (oid==16) //bool { boost::put(*feature,name,buf[0] != 0); } else if (oid==23) //int4 { int val = int4net(buf); boost::put(*feature,name,val); } else if (oid==21) //int2 { int val = int2net(buf); boost::put(*feature,name,val); } else if (oid==20) //int8/BigInt { int val = int8net(buf); boost::put(*feature,name,val); } else if (oid == 700) // float4 { float val; float4net(val,buf); boost::put(*feature,name,val); } else if (oid == 701) // float8 { double val; float8net(val,buf); boost::put(*feature,name,val); } else if (oid==25 || oid==1043) // text or varchar { UnicodeString ustr = tr_->transcode(buf); boost::put(*feature,name,ustr); } else if (oid==1042) { UnicodeString ustr = tr_->transcode(trim_copy(std::string(buf)).c_str()); // bpchar boost::put(*feature,name,ustr); } else if (oid == 1700) // numeric { std::string str = mapnik::numeric2string(buf); try { double val = boost::lexical_cast<double>(str); boost::put(*feature,name,val); } catch (boost::bad_lexical_cast & ex) { std::clog << ex.what() << "\n"; } } else { #ifdef MAPNIK_DEBUG std::clog << "Postgis Plugin: uknown OID = " << oid << " FIXME " << std::endl; #endif } } } return feature; } else { rs_->close(); return feature_ptr(); } }
void mdb_shell::filter_metaprogram() { assert(mp); using boost::starts_with; using boost::ends_with; using boost::trim_copy; using vertex_descriptor = metaprogram::vertex_descriptor; using edge_descriptor = metaprogram::edge_descriptor; using edge_property = metaprogram::edge_property; using discovered_t = metaprogram::discovered_t; static const std::string wrap_prefix = "metashell::impl::wrap<"; static const std::string wrap_suffix = ">"; // TODO this check could be made more strict, // since we now whats inside wrap<...> (mp->get_evaluation_result) auto is_wrap_type = [](const std::string& type) { return starts_with(type, wrap_prefix) && ends_with(type, wrap_suffix); }; std::string env_buffer = env.get(); int line_number = std::count(env_buffer.begin(), env_buffer.end(), '\n'); // First disable everything for (edge_descriptor edge : mp->get_edges()) { mp->get_edge_property(edge).enabled = false; } // We will traverse the interesting edges later std::stack<edge_descriptor> edge_stack; // Enable the interesting root edges for (edge_descriptor edge : mp->get_out_edges(mp->get_root_vertex())) { edge_property& property = mp->get_edge_property(edge); const std::string& target_name = mp->get_vertex_property(mp->get_target(edge)).name; // Filter out edges, that is not instantiated by the entered type if (property.point_of_instantiation.name == internal_file_name && property.point_of_instantiation.row == line_number + 2 && (property.kind == instantiation_kind::template_instantiation || property.kind == instantiation_kind::memoization) && (!is_wrap_type(target_name) || property.kind != instantiation_kind::memoization)) { property.enabled = true; edge_stack.push(edge); } } discovered_t discovered(mp->get_num_vertices()); // Traverse the graph to enable all edges which are reachable from the // edges enabled above while (!edge_stack.empty()) { edge_descriptor edge = edge_stack.top(); edge_stack.pop(); assert(mp->get_edge_property(edge).enabled); vertex_descriptor vertex = mp->get_target(edge); if (discovered[vertex]) { continue; } for (edge_descriptor out_edge : mp->get_out_edges(vertex)) { edge_property& property = mp->get_edge_property(out_edge); if (property.kind == instantiation_kind::template_instantiation || property.kind == instantiation_kind::memoization) { property.enabled = true; edge_stack.push(out_edge); } } } // Unwrap vertex names for (metaprogram::vertex_descriptor vertex : mp->get_vertices()) { std::string& name = mp->get_vertex_property(vertex).name; if (is_wrap_type(name)) { name = trim_copy(name.substr( wrap_prefix.size(), name.size() - wrap_prefix.size() - wrap_suffix.size())); if (!is_template_type(name)) { for (metaprogram::edge_descriptor in_edge : mp->get_in_edges(vertex)) { mp->get_edge_property(in_edge).kind = instantiation_kind::non_template_type; } } } } // Clang sometimes produces equivalent instantiations events from the same // point. Filter out all but one of each for (metaprogram::vertex_descriptor vertex : mp->get_vertices()) { typedef std::tuple<file_location, instantiation_kind, vertex_descriptor> set_element_t; std::set<set_element_t> similar_edges; for (metaprogram::edge_descriptor edge : mp->get_out_edges(vertex)) { metaprogram::edge_property& edge_property = mp->get_edge_property(edge); set_element_t set_element = std::make_tuple( edge_property.point_of_instantiation, edge_property.kind, mp->get_target(edge)); auto it = similar_edges.find(set_element); if (it != similar_edges.end()) { edge_property.enabled = false; } else { similar_edges.insert(set_element); } } } }
void NastranTokenizer::splitFixedFormat(string& line, const bool longFormat, const bool firstLine) { boost::offset_separator f; int fieldMax; if (longFormat) { int offsets[] = { 8, 16, 16, 16, 16, 8 }; fieldMax = 5; f = offset_separator(offsets, offsets + 6); } else { int offsets[] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; fieldMax = 9; f = offset_separator(offsets, offsets + 10); } replaceTabs(line); tokenizer<offset_separator> tok(line, f); tokenizer<offset_separator>::iterator beg = tok.begin(); int count = 0; if (!firstLine) { //todo:check that explicit continuation tokens are the same ++beg; count++; } bool explicitContinuation = false; for (; beg != tok.end(); ++beg) { string trimCopy = trim_copy(*beg); //erase all the long format specifiers if (count == 0) { boost::erase_all(trimCopy, "*"); } currentLineVector.push_back(trimCopy); if (++count == fieldMax) { explicitContinuation = (++beg != tok.end()) && !(trim_copy(*beg).empty()); if (explicitContinuation && this->logLevel >= vega::LogLevel::TRACE) { cout << "explicitContinuation" << endl; } break; } } string line2; if (explicitContinuation) { //todo:check that continuation tokens are the same bool iseof = readLineSkipComment(line2); if (!iseof) { splitFixedFormat(line2, longFormat, false); } else { throw "Continuation Expected: Line N " + this->lineNumber; } } else { //test for automatic continuation char c = static_cast<char>(this->instrream.peek()); if (c == ' ' || c == '+' || c == '*') { readLineSkipComment(line2); //fill the current line with empty fields for (; count < fieldMax; count++) { currentLineVector.push_back(""); } bool longFormat = (c == '*'); splitFixedFormat(line2, longFormat, false); } } }