// Loads a specific setting from the string argument of the function into the member variable that stores that specific setting // in the class. void Settings::loadSettingsFromFile(std::string settingsLine) { // Split the setting into it's name and its value std::string settingName = settingsLine.substr(0, 6); int settingValue; std::istringstream buffer(settingsLine.substr(7)); buffer >> settingValue; // If the setting is volume level... if (settingName == "volPer") { volumePercent = settingValue; } // If the setting is volume muted... else if (settingName == "volMut") { volumeMute = settingValue; } // If the setting is the high score... else if (settingName == "hghScr") { highScore = settingValue; } // If the setting describes a question being active or not... else if (questionSettings.find(stringToEnum(settingName)) != questionSettings.end()) { questionSettings[stringToEnum(settingName)] = settingValue; } // If the setting does not exist... else { std::cout << "Settings file contains illegal characters:" << settingsLine << "\n" << "Ignoring...\n\n"; } }
END_TEST START_TEST(test_getChunkValue) { printf("Get Chunk Value Test(s)\n"); const int num_tests = 5; enum NUMERALS test_cases[5][5]; stringToEnum("MCM", test_cases[0]); stringToEnum("IX", test_cases[1]); stringToEnum("IV", test_cases[2]); stringToEnum("MC", test_cases[3]); stringToEnum("CL", test_cases[4]); const size_t lens[5] = { 1, 2, 2, 1, 1 }; const int isValidCase[] = { 1000, 9, 4, 1000, 100 }; int i; for(i=0; i<num_tests; i++){ ck_assert_int_eq(getChunkValue(test_cases[i], lens[i]), isValidCase[i]); } }
int main(int argc, const char * argv[]) { argc-=(argc>0); argv+=(argc>0); // skip program name argv[0] if present option::Stats stats(usage, argc, argv); option::Option* options = new option::Option[stats.options_max]; option::Option* buffer = new option::Option[stats.buffer_max]; option::Parser parse(usage, argc, argv, options, buffer); if (parse.error()) return 1; if (options[HELP]) { option::printUsage(std::cout, usage); return 0; } if (options[SOLVER] == NULL || options[SOLVER].arg == NULL) { std::cout << std::endl << "\tSolver type is required!" << std::endl << std::endl; option::printUsage(std::cout, usage); return 0; } for (option::Option* opt = options[UNKNOWN]; opt; opt = opt->next()){ std::cout << "Unknown option: " << opt->name << "\n"; } float time; size_t Nx, Ny, N; time = setValue<float>(options,TIME,0.2f); Nx = setValue<size_t>(options,X_SIZE,128); Ny = setValue<size_t>(options,Y_SIZE,128); N = setValue<size_t>(options,N_SIZE,150); AppManager* manager = NULL; try { manager = new AppManager(); manager->init(Nx,Ny,stringToEnum(options[SOLVER].arg),options[DEVICE].arg); manager->begin(N,time); } catch (std::exception& e) { std::cerr << e.what() << std::endl; } delete manager; delete [] options; delete [] buffer; return 0; }
void PlayerItem::readAttributes(const Json::Value& root) { _name = root.get(NAME, "").asString(); if (!root[TAGS].isNull()) { const Json::Value& tags = root[TAGS]; auto tagIt = tags.begin(); const auto tagEnd = tags.end(); for (; tagIt != tagEnd; tagIt++) { if (!(*tagIt).isNull()) { _tags.insert((*tagIt).asString()); } } } float x1 = root[X1].asFloat(); float y1 = root[Y1].asFloat(); float x2 = root[X2].asFloat(); float y2 = root[Y2].asFloat(); const bool fullScreen = root[FULL_SCREEN].asBool(); if (fullScreen) _screenRect.setFullScreen(); else _screenRect.setExtents(x1, y1, x2, y2); _xScale = root[SCALE_X].asFloat(); _yScale = root[SCALE_Y].asFloat(); _zScale = root.get(SCALE_Z, 1.0f).asFloat(); _xPos = root[POSITION_X].asFloat(); _yPos = root[POSITION_Y].asFloat(); _zPos = root.get(POSITION_Z, 0.0f).asFloat(); _zRot = root[ROTATION].asFloat(); _xRot = root.get(ROTATION_X, 0.0f).asFloat(); _yRot = root.get(ROTATION_Y, 0.0f).asFloat(); _xPivot = root.get(PIVOT_X, 0.0f).asFloat(); _yPivot = root.get(PIVOT_Y, 0.0f).asFloat(); _zPivot = root.get(PIVOT_Z, 0.0f).asFloat(); _zorder = root[Z_ORDER].asInt(); _opacity = root.get(OPACITY, 1.0f).asFloat(); if (!root[COMPOSITE_CHILDREN].isNull()) { _compositeChildren = static_cast<TriStateEnabled>(stringToEnum(TriStateEnabledStrings, root[COMPOSITE_CHILDREN].asString())); } _seekable = root[SEEKABLE].asBool(); _startTime = root[START_TIME].asFloat(); _duration = root[DURATION].asFloat(); _playbackStart = root.get(PLAYBACK_START_TIME, 0.0f).asFloat(); _contentMode = static_cast<ContentMode>(stringToEnum(ContentModeStrings, root[CONTENT_MODE].asString())); _gravity = static_cast<Gravity>(stringToEnum(GravityStrings, root[GRAVITY].asString())); if (root[CROP_REGION].isArray() && root[CROP_REGION].size() == 4) { // Crop region as [cx, cy, cw, ch] const Json::Value& crop = root[CROP_REGION]; _cropX = crop[0].asFloat(); _cropY = crop[1].asFloat(); _cropWidth = crop[2].asFloat(); _cropHeight = crop[3].asFloat(); } // Although current default for _focusX,_focusY is 0.5f, 0.3333f // to focus on top third, older json files were based on a different // centering algorithm. Use -1.0f,-1.0f to signify this older algorithm. _focusX = root.get(FOCUS_X, -1.0f).asFloat(); _focusY = root.get(FOCUS_Y, -1.0f).asFloat(); if (!root[BLEND_MODE].isNull()) { _blendMode = static_cast<BlendMode>(stringToEnum(BlendModeStrings, root[BLEND_MODE].asString())); } _volume = root.get(VOLUME, 1.0f).asFloat(); if (!root[ANIMATION].isNull()) _animation = std::dynamic_pointer_cast<Animation>( createObject(root[ANIMATION])); if (!root[TRANSITION_END].isNull()) _endTransition = std::dynamic_pointer_cast<Transition>( createObject(root[TRANSITION_END])); if (!root[FILTER].isNull()) _filter = std::dynamic_pointer_cast<FilterEffect>( createObject(root[FILTER])); if (!root[EFFECT].isNull()) _effect = std::dynamic_pointer_cast<EffectNetwork>( createObject(root[EFFECT])); if (!root[CAMERA].isNull()) _camera = std::dynamic_pointer_cast<CameraView>( createObject(root[CAMERA])); if (!root[RESOURCE].isNull()) _resource = std::dynamic_pointer_cast<IPlayerResource>( createObject(root[RESOURCE])); if (!root[TRANSITION_START].isNull()) _startTransition = std::dynamic_pointer_cast<Transition>(createObject(root[TRANSITION_START])); if (!root[CHILDREN].isNull()) { Json::Value children = root[CHILDREN]; auto childIt = children.begin(); auto childEnd = children.end(); for (; childIt != childEnd; childIt++) { _children.push_back(std::dynamic_pointer_cast<PlayerItem>(createObject(*childIt))); } } }