QVariant getProperty(P_ID id, XmlReader& e) { switch(propertyType(id)) { case P_TYPE::BOOL: return QVariant(bool(e.readInt())); case P_TYPE::SUBTYPE: case P_TYPE::INT: return QVariant(e.readInt()); case P_TYPE::REAL: case P_TYPE::SPATIUM: case P_TYPE::SP_REAL: case P_TYPE::TEMPO: return QVariant(e.readDouble()); case P_TYPE::FRACTION: return QVariant::fromValue(e.readFraction()); case P_TYPE::COLOR: return QVariant(e.readColor()); case P_TYPE::POINT: return QVariant(e.readPoint()); case P_TYPE::SCALE: case P_TYPE::SIZE: return QVariant(e.readSize()); case P_TYPE::STRING: return QVariant(e.readElementText()); case P_TYPE::DIRECTION: { QString value(e.readElementText()); if (value == "up") return QVariant(int(Direction::UP)); else if (value == "down") return QVariant(int(Direction::DOWN)); else if (value == "auto") return QVariant(int(Direction::AUTO)); } break; case P_TYPE::DIRECTION_H: { QString value(e.readElementText()); if (value == "left" || value == "1") return QVariant(int(DirectionH::DH_LEFT)); else if (value == "right" || value == "2") return QVariant(int(DirectionH::DH_RIGHT)); else if (value == "auto") return QVariant(int(DirectionH::DH_AUTO)); } break; case P_TYPE::LAYOUT_BREAK: { QString value(e.readElementText()); if (value == "line") return QVariant(int(LayoutBreak::LayoutBreakType::LINE)); if (value == "page") return QVariant(int(LayoutBreak::LayoutBreakType::PAGE)); if (value == "section") return QVariant(int(LayoutBreak::LayoutBreakType::SECTION)); qDebug("getProperty: invalid P_TYPE::LAYOUT_BREAK: <%s>", qPrintable(value)); } break; case P_TYPE::VALUE_TYPE: { QString value(e.readElementText()); if (value == "offset") return QVariant(int(ValueType::OFFSET_VAL)); else if (value == "user") return QVariant(int(ValueType::USER_VAL)); } break; case P_TYPE::PLACEMENT: { QString value(e.readElementText()); if (value == "above") return QVariant(int(Placement::ABOVE)); else if (value == "below") return QVariant(int(Placement::BELOW)); } break; case P_TYPE::BEAM_MODE: // TODO return QVariant(int(0)); case P_TYPE::GROUPS: { Groups g; g.read(e); return QVariant::fromValue(g); } case P_TYPE::POINT_MM: case P_TYPE::SIZE_MM: case P_TYPE::SYMID: case P_TYPE::TEXT_STYLE: return QVariant(); } return QVariant(); }
void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaObject *metaObject, int revision, Data::Flag propertyFlags, Data::Flag methodFlags, Data::Flag signalFlags) { Q_UNUSED(revision); allowedRevisionCache.append(0); QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); int methodCount = metaObject->methodCount(); // QObject::staticMetaObject.methodCount() to block the destroyed signal and the deleteLater() slot int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset()); methodIndexCache.resize(methodCount); for (int ii = methodOffset; ii < methodCount; ++ii) { QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) continue; QString methodName = QString::fromUtf8(m.methodSignature()); int parenIdx = methodName.indexOf(QLatin1Char('(')); Q_ASSERT(parenIdx != -1); methodName = methodName.left(parenIdx); RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName); methodIndexCache[ii] = data; data->load(m); if (m.methodType() == QMetaMethod::Slot || m.methodType() == QMetaMethod::Method) data->flags |= methodFlags; else if (m.methodType() == QMetaMethod::Signal) data->flags |= signalFlags; data->metaObjectOffset = allowedRevisionCache.count() - 1; if (stringCache.contains(methodName)) { RData *old = stringCache[methodName]; // We only overload methods in the same class, exactly like C++ if (old->flags & Data::IsFunction && old->coreIndex >= methodOffset) data->relatedIndex = old->coreIndex; data->overrideIndexIsProperty = !bool(old->flags & Data::IsFunction); data->overrideIndex = old->coreIndex; stringCache[methodName]->release(); identifierCache[data->identifier.identifier]->release(); } stringCache.insert(methodName, data); identifierCache.insert(data->identifier.identifier, data); data->addref(); data->addref(); } int propCount = metaObject->propertyCount(); int propOffset = metaObject->propertyOffset(); indexCache.resize(propCount); for (int ii = propOffset; ii < propCount; ++ii) { QMetaProperty p = metaObject->property(ii); if (!p.isScriptable()) continue; QString propName = QString::fromUtf8(p.name()); RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName); indexCache[ii] = data; data->load(p, engine); data->flags |= propertyFlags; data->metaObjectOffset = allowedRevisionCache.count() - 1; if (stringCache.contains(propName)) { RData *old = stringCache[propName]; data->overrideIndexIsProperty = !bool(old->flags & Data::IsFunction); data->overrideIndex = old->coreIndex; stringCache[propName]->release(); identifierCache[data->identifier.identifier]->release(); } stringCache.insert(propName, data); identifierCache.insert(data->identifier.identifier, data); data->addref(); data->addref(); } }
// See the License for the specific language governing permissions and // limitations under the License. /** LogicalXorScalar */ #ifndef __NBLA_FUNCTION_LOGICAL_XOR_SCALAR_HPP__ #define __NBLA_FUNCTION_LOGICAL_XOR_SCALAR_HPP__ #include <nbla/function/utils/base_transform_unary.hpp> #include <cmath> namespace nbla { /** @class LogicalXorScalar @brief Taking elementwise logical XOR with scalar. Inputs: - N-D array. Outputs: - N-D array. @tparam T Data type for computation. @param val Value of the scalar. \ingroup FunctionImplGrp */ NBLA_DEFINE_TRANSFORM_UNARY_1_NO_GRAD(LogicalXorScalar, bool(x) ^ a0, bool); } #endif
bool TimeCode::bgf2 () const { return bool (bitField (_time, 31, 31)); }
void CaptureDialog::vulkanLayerWarn_mouseClick() { QString caption = tr("Configure Vulkan layer settings in registry?"); VulkanLayerFlags flags = VulkanLayerFlags::NoFlags; rdcarray<rdcstr> myJSONs; rdcarray<rdcstr> otherJSONs; RENDERDOC_NeedVulkanLayerRegistration(&flags, &myJSONs, &otherJSONs); const bool hasOtherJSON = bool(flags & VulkanLayerFlags::OtherInstallsRegistered); const bool thisRegistered = bool(flags & VulkanLayerFlags::ThisInstallRegistered); const bool needElevation = bool(flags & VulkanLayerFlags::NeedElevation); const bool couldElevate = bool(flags & VulkanLayerFlags::CouldElevate); const bool registerAll = bool(flags & VulkanLayerFlags::RegisterAll); const bool updateAllowed = bool(flags & VulkanLayerFlags::UpdateAllowed); if(flags & VulkanLayerFlags::Unfixable) { QString msg = tr("There is an unfixable problem with your vulkan layer configuration. Please consult the " "RenderDoc documentation, or package/distribution documentation on linux\n\n"); for(const rdcstr &j : otherJSONs) msg += j + lit("\n"); RDDialog::critical(this, tr("Unfixable vulkan layer configuration"), msg); return; } QString msg = tr("Vulkan capture happens through the API's layer mechanism. RenderDoc has detected that "); if(hasOtherJSON) { if(otherJSONs.size() > 1) msg += tr("there are other RenderDoc builds registered already. They must be disabled so that " "capture can happen without nasty clashes."); else msg += tr("there is another RenderDoc build registered already. It must be disabled so that " "capture can happen without nasty clashes."); if(!thisRegistered) msg += tr(" Also "); } if(!thisRegistered) { msg += tr("the layer for this installation is not yet registered. This could be due to an " "upgrade from a version that didn't support Vulkan, or if this version is just a loose " "unzip/dev build."); } msg += tr("\n\nWould you like to proceed with the following changes?\n\n"); if(hasOtherJSON) { for(const rdcstr &j : otherJSONs) msg += (updateAllowed ? tr("Unregister/update: %1\n") : tr("Unregister: %1\n")).arg(j); msg += lit("\n"); } if(!thisRegistered) { if(registerAll) { for(const rdcstr &j : myJSONs) msg += (updateAllowed ? tr("Register/update: %1\n") : tr("Register: %1\n")).arg(j); } else { msg += updateAllowed ? tr("Register one of:\n") : tr("Register/update one of:\n"); for(const rdcstr &j : myJSONs) msg += tr(" -- %1\n").arg(j); } msg += lit("\n"); } msg += tr("This is a one-off change, it won't be needed again unless the installation moves."); QMessageBox::StandardButton install = RDDialog::question(this, caption, msg, RDDialog::YesNoCancel); if(install == QMessageBox::Yes) { bool run = false; bool admin = false; // if we need to elevate, just try it. if(needElevation) { admin = run = true; } // if we could elevate, ask the user else if(couldElevate) { QMessageBox::StandardButton elevate = RDDialog::question( this, tr("System layer install"), tr("Do you want to elevate permissions to install the layer at a system level?"), RDDialog::YesNoCancel); if(elevate == QMessageBox::Yes) admin = true; else if(elevate == QMessageBox::No) admin = false; run = (elevate != QMessageBox::Cancel); } // otherwise run non-elevated else { run = true; } if(run) { if(admin) { RunProcessAsAdmin(qApp->applicationFilePath(), QStringList() << lit("--install_vulkan_layer") << lit("root"), [this]() { ui->vulkanLayerWarn->setVisible(false); }); return; } else { QProcess process; process.start(qApp->applicationFilePath(), QStringList() << lit("--install_vulkan_layer") << lit("user")); process.waitForFinished(300); } } ui->vulkanLayerWarn->setVisible(RENDERDOC_NeedVulkanLayerRegistration(NULL, NULL, NULL)); } }
bool TimeCode::colorFrame () const { return bool (bitField (_time, 7, 7)); }
bool TimeCode::bgf0 () const { return bool (bitField (_time, 23, 23)); }
inline bool Descriptor::is_attached() const noexcept { return bool(m_root_table); }
bool AnalysisClientContext::m_getStatus() const { return bool(m_pathTreeOwner); }
viennacl::ocl::context & opencl_context() { assert(mem_type_ == OPENCL_MEMORY && bool("Context type is not OpenCL")); return *const_cast<viennacl::ocl::context*>( ocl_context_ptr_); }
operator bool() const { return !log_event::operator bool(); }
viennacl::ocl::context const & opencl_context() const { assert(mem_type_ == OPENCL_MEMORY && bool("Context type is not OpenCL")); return *ocl_context_ptr_; }
viennacl::hsa::context const & hsa_context() const { assert(mem_type_ == HSA_MEMORY && bool("Context type is not HSA")); return *hsa_context_ptr_; }
DisplayFilterBase::DisplayFilterBase(void) : Inherited(), _sfEnabled (bool(true)) { }
void OPvPCapturePointNA::UpdateWyvernRoostWorldState(uint32 roost) { switch (roost) { case NA_ROOST_S: m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_SOUTH_NEU_H, uint32(bool(m_WyvernStateSouth & WYVERN_NEU_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_SOUTH_NEU_A, uint32(bool(m_WyvernStateSouth & WYVERN_NEU_ALLIANCE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_SOUTH_H, uint32(bool(m_WyvernStateSouth & WYVERN_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_SOUTH_A, uint32(bool(m_WyvernStateSouth & WYVERN_ALLIANCE))); break; case NA_ROOST_N: m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_NORTH_NEU_H, uint32(bool(m_WyvernStateNorth & WYVERN_NEU_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_NORTH_NEU_A, uint32(bool(m_WyvernStateNorth & WYVERN_NEU_ALLIANCE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_NORTH_H, uint32(bool(m_WyvernStateNorth & WYVERN_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_NORTH_A, uint32(bool(m_WyvernStateNorth & WYVERN_ALLIANCE))); break; case NA_ROOST_W: m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_WEST_NEU_H, uint32(bool(m_WyvernStateWest & WYVERN_NEU_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_WEST_NEU_A, uint32(bool(m_WyvernStateWest & WYVERN_NEU_ALLIANCE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_WEST_H, uint32(bool(m_WyvernStateWest & WYVERN_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_WEST_A, uint32(bool(m_WyvernStateWest & WYVERN_ALLIANCE))); break; case NA_ROOST_E: m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_EAST_NEU_H, uint32(bool(m_WyvernStateEast & WYVERN_NEU_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_EAST_NEU_A, uint32(bool(m_WyvernStateEast & WYVERN_NEU_ALLIANCE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_EAST_H, uint32(bool(m_WyvernStateEast & WYVERN_HORDE))); m_PvP->SendUpdateWorldState(NA_MAP_WYVERN_EAST_A, uint32(bool(m_WyvernStateEast & WYVERN_ALLIANCE))); break; } }
int main(int argc, char *argv[]) { std::ifstream in("lab1.dic", std::ifstream::in); std::istream_iterator<std::string> in_iterator(in), eos; std::vector<std::string> lines(in_iterator, eos); // all lines from file srand(unsigned(time(0))); // for std::random_shuffle std::random_shuffle(lines.begin(), lines.end()); std::list<std::string> lines_list(lines.begin(), lines.end()); // randomised list // // Zad 1 // // // qsort(std::vector) // //std::random_shuffle(lines.begin(), lines.end()); // is already random std::cout << "qsort(std::vector) time: " << get_time<std::vector<std::string> >(lines , [](std::vector<std::string> &x) -> void { qsort(&x[0] , x.size() , sizeof(std::string) , [](const void *x, const void *y) -> int { return ((std::string*)x)->compare(*(std::string*)y); }); }) << "s\n"; // // std::sort(std::vector) // std::random_shuffle(lines.begin(), lines.end()); std::cout << "std::sort(std::vector) time: " << get_time<std::vector<std::string> >(lines , [](std::vector<std::string> &x) -> void { std::sort(x.begin(), x.end()); }) << "s\n"; // // std::stable_sort // std::random_shuffle(lines.begin(), lines.end()); std::cout << "std::stable_sort(std::vector) time: " << get_time<std::vector<std::string> >(lines , [](std::vector<std::string> &x) -> void { std::stable_sort(x.begin(), x.end()); }) << "s\n"; // // std::list::sort() // //std::random_shuffle(lines_list.begin(), lines_list.end()); // cannot apply to list, is already random std::cout << "std::list::sort() time: " << get_time<std::list<std::string> >(lines_list , [](std::list<std::string> &x) -> void { x.sort(); }) << "s\n"; // // Zad 2 // // // std::sort(std::vector) for reversed strings // std::random_shuffle(lines.begin(), lines.end()); std::cout << "std::sort(std::vector) for reversed strings time: " << get_time<std::vector<std::string> >(lines , [](std::vector<std::string> &x) -> void { // Reverse string sorting function std::function<bool(std::string, std::string)> reverse_sorting = [](std::string i, std::string j) -> bool { return std::string(i.rbegin(), i.rend()) < std::string(j.rbegin(), j.rend()); }; std::sort(x.begin(), x.end(), reverse_sorting); }) << "s\n"; // For testing //for(std::string s : lines) //{ // std::cout << s << std::endl; //} return 0; //Huge success! }
bool TimeCode::dropFrame () const { return bool (bitField (_time, 6, 6)); }
void Arkode::ArkodeCore() { _idid = ARKodeReInit(_arkodeMem, NULL, ARK_fCallback, _tCurrent, _ARK_y); _idid = ARKodeSetStopTime(_arkodeMem, _tEnd); _idid = ARKodeSetInitStep(_arkodeMem, 1e-12); if (_idid < 0) throw ModelicaSimulationError(SOLVER,"ARKode::ReInit"); bool writeEventOutput = (_settings->getGlobalSettings()->getOutputPointType() == OPT_ALL); bool writeOutput = !(_settings->getGlobalSettings()->getOutputPointType() == OPT_NONE); while (_solverStatus & ISolver::CONTINUE && !_interrupt ) { _ark_rt = ARKode(_arkodeMem, _tEnd, _ARK_y, &_tCurrent, ARK_ONE_STEP); _idid = ARKodeGetNumSteps(_arkodeMem, &_locStps); //if (_idid != CV_SUCCESS) // throw ModelicaSimulationError(SOLVER,"CVodeGetNumSteps failed. The cvode mem pointer is NULL"); _idid = ARKodeGetLastStep(_arkodeMem, &_h); //if (_idid != CV_SUCCESS) // throw ModelicaSimulationError(SOLVER,"CVodeGetLastStep failed. The cvode mem pointer is NULL"); //Check if there was at least one output-point within the last solver interval // -> Write output if true if (writeOutput) { writeArkodeOutput(_tCurrent, _h, _locStps); } //set completed step to system and check if terminate was called if(_continuous_system->stepCompleted(_tCurrent)) _solverStatus = DONE; // Perform state selection bool state_selection = stateSelection(); if (state_selection) _continuous_system->getContinuousStates(_z); _zeroFound = false; // Check if step was successful /* if (check_flag(&_cv_rt, "CVode", 1)) { _solverStatus = ISolver::SOLVERERROR; break; }*/ // A root was found if ((_ark_rt == ARK_ROOT_RETURN) && !isInterrupted()) { // CVode is setting _tCurrent to the time where the first event occurred double _abs = fabs(_tLastEvent - _tCurrent); _zeroFound = true; if ((_abs < 1e-3) && _event_n == 0) { _tLastEvent = _tCurrent; _event_n++; } else if ((_abs < 1e-3) && (_event_n >= 1 && _event_n < 500)) { _event_n++; } else if ((_abs >= 1e-3)) { //restart event counter _tLastEvent = _tCurrent; _event_n = 0; } else throw ModelicaSimulationError(EVENT_HANDLING,"Number of events exceeded in time interval " + to_string(_abs) + " at time " + to_string(_tCurrent)); // CVode has interpolated the states at time 'tCurrent' _time_system->setTime(_tCurrent); // To get steep steps in the result file, two value points (P1 and P2) must be added // // Y | (P2) X........... // | : // | : // |........X (P1) // |----------------------------------> // | ^ t // _tCurrent // Write the values of (P1) if (writeEventOutput) { _continuous_system->evaluateAll(IContinuous::CONTINUOUS); writeToFile(0, _tCurrent, _h); } _idid = ARKodeGetRootInfo(_arkodeMem, _zeroSign); for (int i = 0; i < _dimZeroFunc; i++) _events[i] = bool(_zeroSign[i]); if (_mixed_system->handleSystemEvents(_events)) { // State variables were reinitialized, thus we have to give these values to the cvode-solver // Take care about the memory regions, _z is the same like _CV_y _continuous_system->getContinuousStates(_z); } } if ((_zeroFound || state_selection)&& !isInterrupted()) { if (writeEventOutput) { _continuous_system->evaluateAll(IContinuous::CONTINUOUS); writeToFile(0, _tCurrent, _h); } _idid = ARKodeReInit(_arkodeMem, NULL, ARK_fCallback, _tCurrent, _ARK_y); if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::ReInit()"); // Der Eventzeitpunkt kann auf der Endzeit liegen (Time-Events). In diesem Fall wird der Solver beendet, da CVode sonst eine interne Warnung if (_tCurrent == _tEnd) _ark_rt = ARK_TSTOP_RETURN; } ++_outStps; _tLastSuccess = _tCurrent; if (_ark_rt == ARK_TSTOP_RETURN) { _time_system->setTime(_tEnd); //Solver has finished calculation - calculate the final values _continuous_system->setContinuousStates(NV_DATA_S(_ARK_y)); _continuous_system->evaluateAll(IContinuous::CONTINUOUS); if(writeOutput) writeToFile(0, _tEnd, _h); _accStps += _locStps; _solverStatus = DONE; } } }
bool TimeCode::fieldPhase () const { return bool (bitField (_time, 15, 15)); }
template<typename T> inline constexpr bool odd(const T a) { return bool(a & 1); }
bool TimeCode::bgf1 () const { return bool (bitField (_time, 30, 30)); }
explicit operator bool() const noexcept { return m_base.operator bool(); }
int main(void) { auto ret_three_hundred_lambda_func = [](){ return 300; }; { //Test default construction cs540::Function<int()> default_constructed; //Test value construction with a free-function cs540::Function<int()> ret_one_hundred(ret_one_hundred_func); //Test value construction with a lambda-function cs540::Function<int()> ret_three_hundred_lambda(ret_three_hundred_lambda_func); //Test value construction with a functor cs540::Function<int()> ret_two_hundred_functor(ret_two_hundred_functor_t{}); //Test function operator on default constructed int testval = 30; try { default_constructed(); } catch(cs540::BadFunctionCall &bfc) { //We modify testval here so that we can assert that a change happened later to make sure an exception was caught testval += 10; } assert(testval == 40); //Test function operator on free-function target, also test that results are correct assert(ret_one_hundred() == ret_one_hundred_func()); //Test function operator on functor target, also test that results are correct assert(ret_two_hundred_functor() == ret_two_hundred_functor_t{}()); //Test function operator on lambda target, also test that results are correct assert(ret_three_hundred_lambda() == ret_three_hundred_lambda_func()); { //Test assignment from Function cs540::Function<int()> tmp; tmp = ret_one_hundred; assert(tmp() == ret_one_hundred_func()); } { //Test assignment from free-function cs540::Function<int()> tmp; tmp = ret_one_hundred_func; assert(tmp() == ret_one_hundred_func()); } { //Test assignment from Function containing functor cs540::Function<int()> tmp; tmp = ret_two_hundred_functor; assert(tmp() == ret_two_hundred_functor_t{}()); } { //Test assignment from functor cs540::Function<int()> tmp; ret_two_hundred_functor_t functor; tmp = functor; assert(tmp() == ret_two_hundred_functor_t{}()); } { //Test assignment from Function containing lambda cs540::Function<int()> tmp; tmp = ret_three_hundred_lambda; assert(tmp() == ret_three_hundred_lambda_func()); } { //Test assignment from lambda cs540::Function<int()> tmp; tmp = ret_three_hundred_lambda_func; assert(tmp() == ret_three_hundred_lambda_func()); } { //Test equality operators assert((!ret_one_hundred.operator bool()) == (ret_one_hundred == nullptr)); assert((!ret_one_hundred.operator bool()) == (nullptr == ret_one_hundred)); //Test equality operators with a default constructed object cs540::Function<void(void)> tmp; assert((!tmp.operator bool()) == (tmp == nullptr)); assert((!tmp.operator bool()) == (nullptr == tmp)); } { //Test inequality operators assert(ret_one_hundred.operator bool() == (ret_one_hundred != nullptr)); assert(ret_one_hundred.operator bool() == (nullptr != ret_one_hundred)); //Test inequality operators with a default constructed object cs540::Function<void()> tmp; assert(false == (tmp != nullptr)); assert(false == (nullptr != tmp)); } { cs540::Function<int()> tmp(ret_one_hundred); assert(ret_one_hundred() == tmp()); tmp = ret_two_hundred_functor; assert(ret_two_hundred_functor() == tmp()); tmp = ret_three_hundred_lambda; assert(ret_three_hundred_lambda() == tmp()); } { //Testing a function that takes arguments cs540::Function<int(int,int)> sum_range(sumrange); assert(sumrange(10,15) == sum_range(10,15)); } { //Testing a recursive lambda that captures a value from the surrounding scope const int a = 30; cs540::Function<int(int)> sum_range = [a,&sum_range](int b) -> int { assert(a<=b); return a==b ? b : b + sum_range(b-1); }; assert(sum_range(40) == sumrange(30,40)); } cout<<"Completed"; } }
int ShuffleTrafficPattern::dest(int source) { assert((source >= 0) && (source < _nodes)); int const shifted = source << 1; return ((shifted & (_nodes - 1)) | bool(shifted & _nodes)); }
// // // /// @brief Checks if the current array is a rank two square array. // /// @return @c true if it is square and @c false otherwise. // constexpr bool is_square() const { return bool(first_rank() == second_rank()); };
bool operator()(const yes_no & lhs, const true_false & rhs) const { return bool(lhs) == bool(rhs); }
void KviApplication::setupBegin() { //We must do the setup...ask the user.. QString szSetupLib; #ifdef KVIRC_MODULES_DIR szSetupLib = KVIRC_MODULES_DIR; #else getGlobalKvircDirectory(szSetupLib, KviApplication::Modules); #endif KviQString::ensureLastCharIs(szSetupLib, KVI_PATH_SEPARATOR_CHAR); #if defined(COMPILE_ON_WINDOWS) szSetupLib.append("kvisetup.dll"); #elif defined(COMPILE_ON_MINGW) szSetupLib.append("libkvisetup.dll"); #else szSetupLib.append("libkvisetup.so"); #endif g_pSetupLibrary = new QLibrary(szSetupLib); if(!g_pSetupLibrary->load()) { KviMessageBox::warning(__tr2qs("Oops! It looks like I can't load modules on this system.\n" "I have been looking for the %s library but I haven't been able to load it\n" "due to the following error: \"%s\"\nAborting."), szSetupLib.toUtf8().data(), g_pSetupLibrary->errorString().toUtf8().data()); #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) ExitProcess(1); #else ::exit(-1); #endif } bool (*sfunc)() = (bool (*)())g_pSetupLibrary->resolve("setup_begin"); if(!sfunc) { KviMessageBox::warning(__tr2qs("Oops! It looks like you have a broken distribution.\n" "The setup module does not export the \"setup_begin\" function.\n" "Aborting!")); #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) ExitProcess(1); #else ::exit(-1); #endif } bool bRet = sfunc(); if(!bRet) { #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) ExitProcess(1); #else ::exit(-1); #endif } }
void OPvPCapturePointNA::FillInitialWorldStates(WorldPacket &data) { if (m_ControllingFaction == ALLIANCE) { data << NA_UI_HORDE_GUARDS_SHOW << uint32(0); data << NA_UI_ALLIANCE_GUARDS_SHOW << uint32(1); } else if (m_ControllingFaction == HORDE) { data << NA_UI_HORDE_GUARDS_SHOW << uint32(1); data << NA_UI_ALLIANCE_GUARDS_SHOW << uint32(0); } else { data << NA_UI_HORDE_GUARDS_SHOW << uint32(0); data << NA_UI_ALLIANCE_GUARDS_SHOW << uint32(0); } data << NA_UI_GUARDS_MAX << NA_GUARDS_MAX; data << NA_UI_GUARDS_LEFT << uint32(m_GuardsAlive); data << NA_UI_TOWER_SLIDER_DISPLAY << uint32(0); data << NA_UI_TOWER_SLIDER_POS << uint32(50); data << NA_UI_TOWER_SLIDER_N << uint32(100); data << NA_MAP_WYVERN_NORTH_NEU_H << uint32(bool(m_WyvernStateNorth & WYVERN_NEU_HORDE)); data << NA_MAP_WYVERN_NORTH_NEU_A << uint32(bool(m_WyvernStateNorth & WYVERN_NEU_ALLIANCE)); data << NA_MAP_WYVERN_NORTH_H << uint32(bool(m_WyvernStateNorth & WYVERN_HORDE)); data << NA_MAP_WYVERN_NORTH_A << uint32(bool(m_WyvernStateNorth & WYVERN_ALLIANCE)); data << NA_MAP_WYVERN_SOUTH_NEU_H << uint32(bool(m_WyvernStateSouth & WYVERN_NEU_HORDE)); data << NA_MAP_WYVERN_SOUTH_NEU_A << uint32(bool(m_WyvernStateSouth & WYVERN_NEU_ALLIANCE)); data << NA_MAP_WYVERN_SOUTH_H << uint32(bool(m_WyvernStateSouth & WYVERN_HORDE)); data << NA_MAP_WYVERN_SOUTH_A << uint32(bool(m_WyvernStateSouth & WYVERN_ALLIANCE)); data << NA_MAP_WYVERN_WEST_NEU_H << uint32(bool(m_WyvernStateWest & WYVERN_NEU_HORDE)); data << NA_MAP_WYVERN_WEST_NEU_A << uint32(bool(m_WyvernStateWest & WYVERN_NEU_ALLIANCE)); data << NA_MAP_WYVERN_WEST_H << uint32(bool(m_WyvernStateWest & WYVERN_HORDE)); data << NA_MAP_WYVERN_WEST_A << uint32(bool(m_WyvernStateWest & WYVERN_ALLIANCE)); data << NA_MAP_WYVERN_EAST_NEU_H << uint32(bool(m_WyvernStateEast & WYVERN_NEU_HORDE)); data << NA_MAP_WYVERN_EAST_NEU_A << uint32(bool(m_WyvernStateEast & WYVERN_NEU_ALLIANCE)); data << NA_MAP_WYVERN_EAST_H << uint32(bool(m_WyvernStateEast & WYVERN_HORDE)); data << NA_MAP_WYVERN_EAST_A << uint32(bool(m_WyvernStateEast & WYVERN_ALLIANCE)); data << NA_MAP_HALAA_NEUTRAL << uint32(bool(m_HalaaState & HALAA_N)); data << NA_MAP_HALAA_NEU_A << uint32(bool(m_HalaaState & HALAA_N_A)); data << NA_MAP_HALAA_NEU_H << uint32(bool(m_HalaaState & HALAA_N_H)); data << NA_MAP_HALAA_HORDE << uint32(bool(m_HalaaState & HALAA_H)); data << NA_MAP_HALAA_ALLIANCE << uint32(bool(m_HalaaState & HALAA_A)); }
Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { uint32_t type = f->get_32(); print_bl("find property of type: " + itos(type)); switch (type) { case VARIANT_NIL: { r_v = Variant(); } break; case VARIANT_BOOL: { r_v = bool(f->get_32()); } break; case VARIANT_INT: { r_v = int(f->get_32()); } break; case VARIANT_INT64: { r_v = int64_t(f->get_64()); } break; case VARIANT_REAL: { r_v = f->get_real(); } break; case VARIANT_DOUBLE: { r_v = f->get_double(); } break; case VARIANT_STRING: { r_v = get_unicode_string(); } break; case VARIANT_VECTOR2: { Vector2 v; v.x = f->get_real(); v.y = f->get_real(); r_v = v; } break; case VARIANT_RECT2: { Rect2 v; v.position.x = f->get_real(); v.position.y = f->get_real(); v.size.x = f->get_real(); v.size.y = f->get_real(); r_v = v; } break; case VARIANT_VECTOR3: { Vector3 v; v.x = f->get_real(); v.y = f->get_real(); v.z = f->get_real(); r_v = v; } break; case VARIANT_PLANE: { Plane v; v.normal.x = f->get_real(); v.normal.y = f->get_real(); v.normal.z = f->get_real(); v.d = f->get_real(); r_v = v; } break; case VARIANT_QUAT: { Quat v; v.x = f->get_real(); v.y = f->get_real(); v.z = f->get_real(); v.w = f->get_real(); r_v = v; } break; case VARIANT_AABB: { AABB v; v.position.x = f->get_real(); v.position.y = f->get_real(); v.position.z = f->get_real(); v.size.x = f->get_real(); v.size.y = f->get_real(); v.size.z = f->get_real(); r_v = v; } break; case VARIANT_MATRIX32: { Transform2D v; v.elements[0].x = f->get_real(); v.elements[0].y = f->get_real(); v.elements[1].x = f->get_real(); v.elements[1].y = f->get_real(); v.elements[2].x = f->get_real(); v.elements[2].y = f->get_real(); r_v = v; } break; case VARIANT_MATRIX3: { Basis v; v.elements[0].x = f->get_real(); v.elements[0].y = f->get_real(); v.elements[0].z = f->get_real(); v.elements[1].x = f->get_real(); v.elements[1].y = f->get_real(); v.elements[1].z = f->get_real(); v.elements[2].x = f->get_real(); v.elements[2].y = f->get_real(); v.elements[2].z = f->get_real(); r_v = v; } break; case VARIANT_TRANSFORM: { Transform v; v.basis.elements[0].x = f->get_real(); v.basis.elements[0].y = f->get_real(); v.basis.elements[0].z = f->get_real(); v.basis.elements[1].x = f->get_real(); v.basis.elements[1].y = f->get_real(); v.basis.elements[1].z = f->get_real(); v.basis.elements[2].x = f->get_real(); v.basis.elements[2].y = f->get_real(); v.basis.elements[2].z = f->get_real(); v.origin.x = f->get_real(); v.origin.y = f->get_real(); v.origin.z = f->get_real(); r_v = v; } break; case VARIANT_COLOR: { Color v; v.r = f->get_real(); v.g = f->get_real(); v.b = f->get_real(); v.a = f->get_real(); r_v = v; } break; case VARIANT_NODE_PATH: { Vector<StringName> names; Vector<StringName> subnames; bool absolute; int name_count = f->get_16(); uint32_t subname_count = f->get_16(); absolute = subname_count & 0x8000; subname_count &= 0x7FFF; if (ver_format < FORMAT_VERSION_NO_NODEPATH_PROPERTY) { subname_count += 1; // has a property field, so we should count it as well } for (int i = 0; i < name_count; i++) names.push_back(_get_string()); for (uint32_t i = 0; i < subname_count; i++) subnames.push_back(_get_string()); NodePath np = NodePath(names, subnames, absolute); r_v = np; } break; case VARIANT_RID: { r_v = f->get_32(); } break; case VARIANT_OBJECT: { uint32_t type = f->get_32(); switch (type) { case OBJECT_EMPTY: { //do none } break; case OBJECT_INTERNAL_RESOURCE: { uint32_t index = f->get_32(); String path = res_path + "::" + itos(index); RES res = ResourceLoader::load(path); if (res.is_null()) { WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); } r_v = res; } break; case OBJECT_EXTERNAL_RESOURCE: { //old file format, still around for compatibility String type = get_unicode_string(); String path = get_unicode_string(); if (path.find("://") == -1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } if (remaps.find(path)) { path = remaps[path]; } RES res = ResourceLoader::load(path, type); if (res.is_null()) { WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); } r_v = res; } break; case OBJECT_EXTERNAL_RESOURCE_INDEX: { //new file format, just refers to an index in the external list int erindex = f->get_32(); if (erindex < 0 || erindex >= external_resources.size()) { WARN_PRINT("Broken external resource! (index out of size"); r_v = Variant(); } else { String type = external_resources[erindex].type; String path = external_resources[erindex].path; if (path.find("://") == -1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } RES res = ResourceLoader::load(path, type); if (res.is_null()) { WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); } r_v = res; } } break; default: { ERR_FAIL_V(ERR_FILE_CORRUPT); } break; } } break; case VARIANT_DICTIONARY: { uint32_t len = f->get_32(); Dictionary d; //last bit means shared len &= 0x7FFFFFFF; for (uint32_t i = 0; i < len; i++) { Variant key; Error err = parse_variant(key); ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); Variant value; err = parse_variant(value); ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); d[key] = value; } r_v = d; } break; case VARIANT_ARRAY: { uint32_t len = f->get_32(); Array a; //last bit means shared len &= 0x7FFFFFFF; a.resize(len); for (uint32_t i = 0; i < len; i++) { Variant val; Error err = parse_variant(val); ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT); a[i] = val; } r_v = a; } break; case VARIANT_RAW_ARRAY: { uint32_t len = f->get_32(); PoolVector<uint8_t> array; array.resize(len); PoolVector<uint8_t>::Write w = array.write(); f->get_buffer(w.ptr(), len); _advance_padding(len); w = PoolVector<uint8_t>::Write(); r_v = array; } break; case VARIANT_INT_ARRAY: { uint32_t len = f->get_32(); PoolVector<int> array; array.resize(len); PoolVector<int>::Write w = array.write(); f->get_buffer((uint8_t *)w.ptr(), len * 4); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len; i++) { ptr[i] = BSWAP32(ptr[i]); } } #endif w = PoolVector<int>::Write(); r_v = array; } break; case VARIANT_REAL_ARRAY: { uint32_t len = f->get_32(); PoolVector<real_t> array; array.resize(len); PoolVector<real_t>::Write w = array.write(); f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t)); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len; i++) { ptr[i] = BSWAP32(ptr[i]); } } #endif w = PoolVector<real_t>::Write(); r_v = array; } break; case VARIANT_STRING_ARRAY: { uint32_t len = f->get_32(); PoolVector<String> array; array.resize(len); PoolVector<String>::Write w = array.write(); for (uint32_t i = 0; i < len; i++) w[i] = get_unicode_string(); w = PoolVector<String>::Write(); r_v = array; } break; case VARIANT_VECTOR2_ARRAY: { uint32_t len = f->get_32(); PoolVector<Vector2> array; array.resize(len); PoolVector<Vector2>::Write w = array.write(); if (sizeof(Vector2) == 8) { f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t) * 2); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 2; i++) { ptr[i] = BSWAP32(ptr[i]); } } #endif } else { ERR_EXPLAIN("Vector2 size is NOT 8!"); ERR_FAIL_V(ERR_UNAVAILABLE); } w = PoolVector<Vector2>::Write(); r_v = array; } break; case VARIANT_VECTOR3_ARRAY: { uint32_t len = f->get_32(); PoolVector<Vector3> array; array.resize(len); PoolVector<Vector3>::Write w = array.write(); if (sizeof(Vector3) == 12) { f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t) * 3); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 3; i++) { ptr[i] = BSWAP32(ptr[i]); } } #endif } else { ERR_EXPLAIN("Vector3 size is NOT 12!"); ERR_FAIL_V(ERR_UNAVAILABLE); } w = PoolVector<Vector3>::Write(); r_v = array; } break; case VARIANT_COLOR_ARRAY: { uint32_t len = f->get_32(); PoolVector<Color> array; array.resize(len); PoolVector<Color>::Write w = array.write(); if (sizeof(Color) == 16) { f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t) * 4); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 4; i++) { ptr[i] = BSWAP32(ptr[i]); } } #endif } else { ERR_EXPLAIN("Color size is NOT 16!"); ERR_FAIL_V(ERR_UNAVAILABLE); } w = PoolVector<Color>::Write(); r_v = array; } break; #ifndef DISABLE_DEPRECATED case VARIANT_IMAGE: { uint32_t encoding = f->get_32(); if (encoding == IMAGE_ENCODING_EMPTY) { r_v = Ref<Image>(); break; } else if (encoding == IMAGE_ENCODING_RAW) { uint32_t width = f->get_32(); uint32_t height = f->get_32(); uint32_t mipmaps = f->get_32(); uint32_t format = f->get_32(); const uint32_t format_version_shift = 24; const uint32_t format_version_mask = format_version_shift - 1; uint32_t format_version = format >> format_version_shift; const uint32_t current_version = 0; if (format_version > current_version) { ERR_PRINT("Format version for encoded binary image is too new"); return ERR_PARSE_ERROR; } Image::Format fmt = Image::Format(format & format_version_mask); //if format changes, we can add a compatibility bit on top uint32_t datalen = f->get_32(); PoolVector<uint8_t> imgdata; imgdata.resize(datalen); PoolVector<uint8_t>::Write w = imgdata.write(); f->get_buffer(w.ptr(), datalen); _advance_padding(datalen); w = PoolVector<uint8_t>::Write(); Ref<Image> image; image.instance(); image->create(width, height, mipmaps, fmt, imgdata); r_v = image; } else { //compressed PoolVector<uint8_t> data; data.resize(f->get_32()); PoolVector<uint8_t>::Write w = data.write(); f->get_buffer(w.ptr(), data.size()); w = PoolVector<uint8_t>::Write(); Ref<Image> image; if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) { image = Image::lossy_unpacker(data); } else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) { image = Image::lossless_unpacker(data); } _advance_padding(data.size()); r_v = image; } } break;
DataStorageImplementation* CpuMemoryStorage:: newInstance( DataStorageVoid* p ) { return new CpuMemoryStorage( p, bool(), bool() ); }