示例#1
0
void SystemSettings::allocationTest() {
    auto module = InviwoApplication::getPtr()->getModuleByType<InviwoCore>();
    if (!module) return;

    auto sysInfo = getTypeFromVector<SystemCapabilities>(module->getCapabilities());

    if (sysInfo) {
        IntProperty* useRAMPercent =
            dynamic_cast<IntProperty*>(getPropertyByIdentifier("useRAMPercent"));
        glm::u64 memBytesAlloc = sysInfo->getAvailableMemory();  // In Bytes
        LogInfo("Maximum Available Memory is " << formatBytesToString(memBytesAlloc));
        memBytesAlloc /= 100;                   // 1% of total available memory
        memBytesAlloc *= useRAMPercent->get();  //?% of total available memory

        try {
            allocTest_ = new glm::u32[static_cast<glm::u32>(memBytesAlloc / 4)];
            LogInfo("Allocated " << formatBytesToString(memBytesAlloc) << ", which is "
                                 << useRAMPercent->get() << "% of available memory");
            delete allocTest_;
        } catch (std::bad_alloc&) {
            LogError("Failed allocation of " << formatBytesToString(memBytesAlloc) << ", which is "
                                             << useRAMPercent->get() << "% of available memory");
        }
    }
}
示例#2
0
Property* PropertyOwner::getPropertyByPath(const std::vector<std::string>& path) const {
    Property* property = getPropertyByIdentifier(path[0]);
    if (property) {
        size_t i = 1;
        while (path.size() > i) {
            CompositeProperty* comp = dynamic_cast<CompositeProperty*>(property);
            if (comp) {
                property = comp->getPropertyByIdentifier(path[i]);
                if (!property) return nullptr;
            } else {
                return nullptr;
            }
            ++i;
        }
        return property;
    }
    return nullptr;
}
示例#3
0
void PropertyOwner::addProperty(Property* property, bool owner) {
    if (getPropertyByIdentifier(property->getIdentifier()) != nullptr) {
        throw Exception(
            "Can't add property identifier, " + property->getIdentifier() + " already exist",
            IvwContext);
    }

    notifyObserversWillAddProperty(property, properties_.size());
    properties_.push_back(property);
    property->setOwner(this);

    if (dynamic_cast<EventProperty*>(property)) {
        eventProperties_.push_back(static_cast<EventProperty*>(property));
    }
    if (dynamic_cast<CompositeProperty*>(property)) {
        compositeProperties_.push_back(static_cast<CompositeProperty*>(property));
    }

    if (owner) {  // Assume ownership of property;
        ownedProperties_.emplace_back(property);
    }
    notifyObserversDidAddProperty(property, properties_.size() - 1);
}
示例#4
0
bool LinkSettings::isLinkable(const Property* property) const {
    if (auto prop = getPropertyByIdentifier("link-" + property->getClassIdentifier(), true)) {
        if (auto linkOption = dynamic_cast<BoolProperty*>(prop)) return linkOption->get();
    }
    return false;
}