void InputManager::retrieve() { for (int i = 0; i < InputAction::TOTAL; i++) { #ifdef USE_SDL2 const std::string cf = std::string("sdl2") + inputActionData[i].configField; #else const std::string cf = inputActionData[i].configField; #endif if (!cf.empty()) { mNameMap[cf] = i; InputFunction &kf = mKey[i]; const std::string keyStr = config.getValue(cf, ""); const size_t keyStrSize = keyStr.size(); if (keyStr.empty()) continue; StringVect keys; splitToStringVector(keys, keyStr, ','); unsigned int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < inputFunctionSize; ++ it) { std::string keyStr2 = *it; if (keyStrSize < 2) continue; int type = InputType::KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { switch (keyStr2[0]) { case 'm': type = InputType::MOUSE; break; case 'j': type = InputType::JOYSTICK; break; default: break; } keyStr2 = keyStr2.substr(1); } const int key = atoi(keyStr2.c_str()); if (key >= -255 && key < SDLK_LAST) { kf.values[i2] = InputItem(type, key); i2 ++; } } } } }
void ModeListModel::addCustomMode(std::string mode) { StringVectCIter it = mVideoModes.begin(); StringVectCIter it_end = mVideoModes.end(); while (it != it_end) { if (*it == mode) return; ++ it; } mVideoModes.push_back(mode); }
int main(int argc, char * argv[]) { bool pass = true; { StringVect perms = permutation_str_no_dup(""); pass = pass && perms.empty(); } { StringVect perms = permutation_str_no_dup("a"); pass = pass && (perms.size() == 1) && (std::find(perms.begin(), perms.end(), "a") != perms.end()) ; } { StringVect perms = permutation_str_no_dup("ab"); pass = pass && (perms.size() == 2) && (std::find(perms.begin(), perms.end(), "ab") != perms.end()) && (std::find(perms.begin(), perms.end(), "ba") != perms.end()) ; } { StringVect perms = permutation_str_no_dup("abc"); pass = pass && (perms.size() == 6) && (std::find(perms.begin(), perms.end(), "abc") != perms.end()) && (std::find(perms.begin(), perms.end(), "acb") != perms.end()) && (std::find(perms.begin(), perms.end(), "bac") != perms.end()) && (std::find(perms.begin(), perms.end(), "bca") != perms.end()) && (std::find(perms.begin(), perms.end(), "cab") != perms.end()) && (std::find(perms.begin(), perms.end(), "cba") != perms.end()) ; } return (pass ? 0 : -1); }
void InputManager::retrieve() { for (int i = 0; i < Input::KEY_TOTAL; i++) { if (*keyData[i].configField) { KeyFunction &kf = mKey[i]; std::string keyStr = config.getValue(keyData[i].configField, ""); if (keyStr.empty()) continue; StringVect keys; splitToStringVector(keys, keyStr, ','); int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < KeyFunctionSize; ++ it) { std::string keyStr2 = *it; if (keyStr.size() < 2) continue; int type = INPUT_KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { switch (keyStr2[0]) { case 'm': type = INPUT_MOUSE; break; case 'j': type = INPUT_JOYSTICK; break; default: break; } keyStr2 = keyStr2.substr(1); } int key = atoi(keyStr2.c_str()); if (key >= -255 && key < SDLK_LAST) { kf.values[i2] = KeyItem(type, key); i2 ++; } } } } }
/*---------------------------------------------------------------------------------------------------------------------- | Saves simulated data stored in `sim_pattern_map' to a file named `filename'. If the file already exists, it will be | overwritten without warning. If the file does not yet exist, it will be created. The file written will be a valid | NEXUS data file suitable for executing in phylogenetic analysis software that reads the NEXUS file format. The | supplied `taxon_names' will be used in the matrix command of the NEXUS file to specify the names of the taxa. | Assumes that the number of elements in `taxon_names' equals `pattern_length'. The `datatype' argument should be the | correct NEXUS datatype (e.g. "dna", "standard") for the data simulated. The symbols used for the states are | supplied in the `state_symbols' vector. Each element of this vector should be a single-character string. Assumes | that no state in any pattern stored in `sim_pattern_map' is greater than or equal to the length of the | `state_symbols' vector (because states are used as indices into `state_symbols'). */ void SimData::saveToNexusFile( const std::string filename, /**< is the name of the file to create containing the simulated data stored in this object */ const StringVect & taxon_names, /**< is a vector containing the taxon names to use in the saved file */ const std::string datatype, /**< is a string to be used as the NEXUS datatype (e.g. "dna" or "standard") */ const StringVect & state_symbols) /**< is a vector of strings representing states (e.g. {"A", "C", "G", "T"}). Note that each state symbol should be a string of length 1 (i.e. a single character) */ { std::cerr << "taxon_names size = " << taxon_names.size() << std::endl; std::cerr << "pattern_length = " << pattern_length << std::endl; std::cerr << "taxon_names: |"; std::copy(taxon_names.begin(), taxon_names.end(), std::ostream_iterator<std::string>(std::cerr, "|")); PHYCAS_ASSERT(state_symbols.size() > 0); PHYCAS_ASSERT(taxon_names.size() == pattern_length); // Find length of longest string in taxon_names vector; this is used later for formatting purposes // The 2 is included in case apostrophes are needed when taxon names are output in the matrix command unsigned length_of_longest_name = 2 + (unsigned)std::max_element(taxon_names.begin(), taxon_names.end(), StringLengthLess())->length(); std::ofstream outf(filename.c_str()); outf << "#nexus" << "\n\n"; outf << "begin data;" << "\n"; outf << str(boost::format(" dimensions ntax=%d nchar=%d;") % pattern_length % (unsigned)total_count) << "\n"; outf << " format datatype=" << datatype << ";" << "\n"; outf << " matrix" << "\n"; // Create a format string to use with boost::format that left-justifies (the "-" flag) the // taxon names in a field of width length_of_longest_name std::string fmtstr = str(boost::format(" %%-%ds") % length_of_longest_name); for (unsigned i = 0; i < pattern_length; ++i) { if (taxon_names[i].find(' ') != std::string::npos) { std::string s = "'"; s += taxon_names[i]; s += "'"; outf << str(boost::format(fmtstr) % s) << " "; } else { outf << str(boost::format(fmtstr) % taxon_names[i]) << " "; } #if 1 // Spit out characters in the order in which they were simulated. While this is a nice feature, // it currently requires storing the data twice (patternVect and sim_pattern_map) unsigned nchar = (unsigned)patternVect.size(); for (unsigned k = 0; k < nchar; ++k) { unsigned j = (unsigned)patternVect[k][i]; char s = state_symbols[j][0]; outf << s; } #else for (pattern_map_t::iterator it = sim_pattern_map.begin(); it != sim_pattern_map.end(); ++it) { // The first member of it is the state, which must be converted from its coded form // to the standard symbol for this data type (e.g. A, C, G or T for DNA characters) int8_t j = (*it).first[i]; PHYCAS_ASSERT(j < (int8_t)state_symbols.size()); char s = state_symbols[j][0]; // use the first (and hopefully only) character in the string at position j // The second member of it is the pattern count unsigned n = (unsigned)it->second; //@POL assuming counts not fractional for (unsigned k = 0; k < n; ++k) { outf << s; } } #endif outf << "\n"; } outf << " ;" << "\n"; outf << "end;" << "\n"; outf.close(); }
void SpriteDef::loadAnimation(XmlNodePtr animationNode, Action *action, ImageSet *imageSet, int variant_offset) { if (!action || !imageSet) return; const std::string directionName = XML::getProperty(animationNode, "direction", ""); const SpriteDirection directionType = makeSpriteDirection(directionName); if (directionType == DIRECTION_INVALID) { logger->log("Warning: Unknown direction \"%s\" used in %s", directionName.c_str(), getIdPath().c_str()); return; } Animation *animation = new Animation; action->setAnimation(directionType, animation); // Get animation frames for_each_xml_child_node(frameNode, animationNode) { const int delay = XML::getIntProperty( frameNode, "delay", 0, 0, 100000); int offsetX = XML::getProperty(frameNode, "offsetX", 0) + imageSet->getOffsetX(); int offsetY = XML::getProperty(frameNode, "offsetY", 0) + imageSet->getOffsetY(); int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100); offsetY -= imageSet->getHeight() - 32; offsetX -= imageSet->getWidth() / 2 - 16; if (xmlNameEqual(frameNode, "frame")) { const int index = XML::getProperty(frameNode, "index", -1); if (index < 0) { logger->log1("No valid value for 'index'"); continue; } Image *img = imageSet->get(index + variant_offset); if (!img) { logger->log("No image at index %d", index + variant_offset); continue; } animation->addFrame(img, delay, offsetX, offsetY, rand); } else if (xmlNameEqual(frameNode, "sequence")) { const int start = XML::getProperty(frameNode, "start", -1); const int end = XML::getProperty(frameNode, "end", -1); const std::string value = XML::getProperty(frameNode, "value", ""); int repeat = XML::getIntProperty(frameNode, "repeat", 1, 0, 100); if (repeat < 1) { logger->log1("No valid value for 'repeat'"); continue; } if (value.empty()) { if (addSequence(start, end, delay, offsetX, offsetY, variant_offset, repeat, rand, imageSet, animation)) { continue; } } else { StringVect vals; splitToStringVector(vals, value, ','); for (StringVectCIter it = vals.begin(), it_end = vals.end(); it != it_end; ++ it) { std::string str = *it; size_t idx = str.find("-"); if (str == "p") { animation->addPause(delay, rand); } else if (idx != std::string::npos) { int v1 = atoi(str.substr(0, idx).c_str()); int v2 = atoi(str.substr(idx + 1).c_str()); addSequence(v1, v2, delay, offsetX, offsetY, variant_offset, repeat, rand, imageSet, animation); } else { Image *img = imageSet->get(atoi( str.c_str()) + variant_offset); if (img) { animation->addFrame(img, delay, offsetX, offsetY, rand); } } } } } else if (xmlNameEqual(frameNode, "pause")) { animation->addPause(delay, rand); } else if (xmlNameEqual(frameNode, "end")) { animation->addTerminator(rand); } else if (xmlNameEqual(frameNode, "jump")) { animation->addJump(XML::getProperty( frameNode, "action", ""), rand); } else if (xmlNameEqual(frameNode, "label")) { std::string name = XML::getProperty(frameNode, "name", ""); if (!name.empty()) animation->addLabel(name); } else if (xmlNameEqual(frameNode, "goto")) { std::string name = XML::getProperty(frameNode, "label", ""); if (!name.empty()) animation->addGoto(name, rand); } } // for frameNode }