Example #1
0
std::unique_ptr<Value>
FunctionValueNode::getValue(std::unique_ptr<Value> val) const
{
    switch (val->getType()) {
        case Value::String:
        {
            StringValue& sval(static_cast<StringValue&>(*val));
            if (_function == LOWERCASE) {
                return std::unique_ptr<Value>(new StringValue(
                    vespalib::LowerCase::convert(sval.getValue())));
            } else if (_function == HASH) {
                return std::unique_ptr<Value>(new IntegerValue(
                    hash(sval.getValue().c_str(), sval.getValue().size()),
                    false));
            }
            break;
        }
        case Value::Float:
        {
            FloatValue& fval(static_cast<FloatValue&>(*val));
            if (_function == HASH) {
                FloatValue::ValueType ffval = fval.getValue();
                return std::unique_ptr<Value>(new IntegerValue(
                    hash(&ffval, sizeof(ffval)), false));
            } else if (_function == ABS) {
                FloatValue::ValueType ffval = fval.getValue();
                if (ffval < 0) ffval *= -1;
                return std::unique_ptr<Value>(new FloatValue(ffval));
            }
            break;
        }
        case Value::Integer:
        {
            IntegerValue& ival(static_cast<IntegerValue&>(*val));
            if (_function == HASH) {
                IntegerValue::ValueType iival = ival.getValue();
                return std::unique_ptr<Value>(new IntegerValue(
                    hash(&iival, sizeof(iival)), false));
            } else if (_function == ABS) {
                IntegerValue::ValueType iival = ival.getValue();
                if (iival < 0) iival *= -1;
                return std::unique_ptr<Value>(new IntegerValue(iival, false));
            }
            break;
        }
        case Value::Bucket:
        {
            throw ParsingFailedException(
                    "No functioncalls are allowed on value of type bucket",
                    VESPA_STRLOC);
            break;
        }

        case Value::Array: break;
        case Value::Struct: break;
        case Value::Invalid: break;
        case Value::Null: break;
    }
    return std::unique_ptr<Value>(new InvalidValue);
}
Example #2
0
// rhsExpr ::= (BIN_OP primaryExpr)*
std::unique_ptr<Expr> FlowParser::rhsExpr(std::unique_ptr<Expr> lhs, int lastPrecedence)
{
	FNTRACE();

	for (;;) {
		// quit if this is not a binOp *or* its binOp-precedence is lower than the 
		// minimal-binOp-requirement of our caller
		int thisPrecedence = binopPrecedence(token());
		if (thisPrecedence <= lastPrecedence)
			return lhs;

		FlowToken binaryOperator = token();
		nextToken();

		std::unique_ptr<Expr> rhs = powExpr();
		if (!rhs)
			return nullptr;

		int nextPrecedence = binopPrecedence(token());
		if (thisPrecedence < nextPrecedence) {
			rhs = rhsExpr(std::move(rhs), thisPrecedence + 0);
			if (!rhs)
				return nullptr;
		}

        Opcode opc = makeOperator(binaryOperator, lhs.get(), rhs.get());
        if (opc == Opcode::EXIT) {
            reportError("Type error in binary expression (%s versus %s).",
                        tos(lhs->getType()).c_str(), tos(rhs->getType()).c_str());
            return nullptr;
        }

		lhs = std::make_unique<BinaryExpr>(opc, std::move(lhs), std::move(rhs));
	}
}
void InputIPv6Handler::handleRequest(std::unique_ptr<Request> r) {
	if (r->getType() == "IPv6" && r->getDirection() == INPUT){
		_logObserver->notify("Handled by InputIPv6Handler");
	}
	else {
		_successor->registerLogObserver(_logObserver);
		_successor->handleRequest(std::move(r));
	}
}
void AbstractAudioInterface::emitAudioPacket(const void* audioData, size_t bytes, quint16& sequenceNumber, const Transform& transform, PacketType packetType) {
    static std::mutex _mutex;
    using Locker = std::unique_lock<std::mutex>;
    auto nodeList = DependencyManager::get<NodeList>();
    SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
    if (audioMixer && audioMixer->getActiveSocket()) {
        Locker lock(_mutex);
        static std::unique_ptr<NLPacket> audioPacket = NLPacket::create(PacketType::Unknown);
        quint8 isStereo = bytes == AudioConstants::NETWORK_FRAME_BYTES_STEREO ? 1 : 0;
        audioPacket->setType(packetType);
        // reset the audio packet so we can start writing
        audioPacket->reset();
        // write sequence number
        audioPacket->writePrimitive(sequenceNumber++);
        if (audioPacket->getType() == PacketType::SilentAudioFrame) {
            // pack num silent samples
            quint16 numSilentSamples = isStereo ?
                AudioConstants::NETWORK_FRAME_SAMPLES_STEREO :
                AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL;
            audioPacket->writePrimitive(numSilentSamples);
        } else {
            // set the mono/stereo byte
            audioPacket->writePrimitive(isStereo);
        }

        // pack the three float positions
        audioPacket->writePrimitive(transform.getTranslation());
        // pack the orientation
        audioPacket->writePrimitive(transform.getRotation());

        if (audioPacket->getType() != PacketType::SilentAudioFrame) {
            // audio samples have already been packed (written to networkAudioSamples)
            audioPacket->setPayloadSize(audioPacket->getPayloadSize() + bytes);
            static const int leadingBytes = sizeof(quint16) + sizeof(glm::vec3) + sizeof(glm::quat) + sizeof(quint8);
            memcpy(audioPacket->getPayload() + leadingBytes, audioData, bytes);
        }
        nodeList->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendAudioPacket);
        nodeList->sendUnreliablePacket(*audioPacket, *audioMixer);
    }
}
Example #5
0
bool
is_composite(const std::unique_ptr<Value>& val)
{
    if (not val)
        return false;

    switch (val->getType()) {
    case Value::MAP:
    case Value::SET:
    case Value::MATRIX:
        return true;

    default:
        return false;
    }
}
Example #6
0
void Connection::processControl(std::unique_ptr<ControlPacket> controlPacket) {
    
    // Simple dispatch to control packets processing methods based on their type.
    
    // Processing of control packets (other than Handshake / Handshake ACK)
    // is not performed if the handshake has not been completed.
    
    switch (controlPacket->getType()) {
        case ControlPacket::ACK:
            if (_hasReceivedHandshakeACK) {
                processACK(move(controlPacket));
            }
            break;
        case ControlPacket::LightACK:
            if (_hasReceivedHandshakeACK) {
                processLightACK(move(controlPacket));
            }
            break;
        case ControlPacket::ACK2:
            if (_hasReceivedHandshake) {
                processACK2(move(controlPacket));
            }
            break;
        case ControlPacket::NAK:
            if (_hasReceivedHandshakeACK) {
                processNAK(move(controlPacket));
            }
            break;
        case ControlPacket::TimeoutNAK:
            if (_hasReceivedHandshakeACK) {
                processTimeoutNAK(move(controlPacket));
            }
            break;
        case ControlPacket::Handshake:
            processHandshake(move(controlPacket));
            break;
        case ControlPacket::HandshakeACK:
            processHandshakeACK(move(controlPacket));
            break;
        case ControlPacket::ProbeTail:
            if (_isReceivingData) {
                processProbeTail(move(controlPacket));
            }
            break;
    }
}
Example #7
0
  void TokenFactory::updateFromJson(const std::unique_ptr<TokenInfo> &tokenInfo, const std::string jsonStr)
  {
    if(jsonStr.empty()) return;

    jsonxx::Object jsonRoot;

    assert(jsonRoot.parse(jsonStr));

    //check that json object has all needed information
    assert(jsonRoot.has<jsonxx::String>("access_token"));
    assert(jsonRoot.has<jsonxx::String>("token_type"));
    assert(jsonRoot.has<jsonxx::Number>("expires_in"));

    std::string tokenType = jsonRoot.get<jsonxx::String>("token_type");
    assert(tokenInfo->getType() == tokenType);
    tokenInfo->setAccessToken(jsonRoot.get<jsonxx::String>("access_token"));
    tokenInfo->expiresIn(jsonRoot.get<jsonxx::Number>("expires_in"));
  }
Example #8
0
void 
PropertyManager::addAttribute(wxPropertyGridManager *pg, std::unique_ptr<Attribute> &a) {

	switch (a->getType()) {

	case Enums::ENUM: createEnum(pg, a); break;
	case Enums::BOOL: createBool(pg, a); break;
	case Enums::BVEC4: createBVec4(pg, a); break;
	case Enums::INT: createInt(pg, a); break;
	case Enums::IVEC3: createIVec3(pg, a); break;
	case Enums::UINT: createUInt(pg, a); break;
	case Enums::UIVEC2: createUIVec2(pg, a); break;
	case Enums::UIVEC3: createUIVec3(pg, a); break;
	case Enums::FLOAT: createFloat(pg, a); break;
	case Enums::VEC2: createVec2(pg, a); break;
	case Enums::VEC3: createVec3(pg, a); break;
	case Enums::VEC4: createVec4(pg, a); break;
	case Enums::MAT3: createMat3(pg, a); break;
	case Enums::MAT4: createMat4(pg, a); break;
	case Enums::STRING: createString(pg, a); break;
	default: assert(false && "Missing datatype in property manager");

	}
}
Example #9
0
 Let(Bindings bindings_, std::unique_ptr<Expression> result_) :
     Expression(Kind::Let, result_->getType()),
     bindings(std::move(bindings_)),
     result(std::move(result_))
 {}
Example #10
0
std::unique_ptr<Value>
ArithmeticValueNode::traceValue(std::unique_ptr<Value> lval,
                                std::unique_ptr<Value> rval,
                                std::ostream& out) const
{
    switch (_operator) {
        case ADD:
        {
            if (lval->getType() == Value::String &&
                rval->getType() == Value::String)
            {
                StringValue& slval(static_cast<StringValue&>(*lval));
                StringValue& srval(static_cast<StringValue&>(*rval));
                std::unique_ptr<Value> result(new StringValue(
                            slval.getValue() + srval.getValue()));
                out << "Appended strings '" << slval << "' + '" << srval
                    << "' -> '" << *result << "'.\n";
                return result;
            }
        }
        [[fallthrough]];
        case SUB:
        case MUL:
        case DIV:
        {
            if (lval->getType() == Value::Integer &&
                rval->getType() == Value::Integer)
            {
                IntegerValue& ilval(static_cast<IntegerValue&>(*lval));
                IntegerValue& irval(static_cast<IntegerValue&>(*rval));
                IntegerValue::ValueType res = 0;
                switch (_operator) {
                    case ADD: res = ilval.getValue() + irval.getValue(); break;
                    case SUB: res = ilval.getValue() - irval.getValue(); break;
                    case MUL: res = ilval.getValue() * irval.getValue(); break;
                    case DIV: res = ilval.getValue() / irval.getValue(); break;
                    case MOD: assert(0);
                }
                std::unique_ptr<Value> result(new IntegerValue(res, false));
                out << "Performed integer operation " << ilval << " "
                    << getOperatorName() << " " << irval << " = " << *result
                    << "\n";
                return result;
            }
            NumberValue* nlval(dynamic_cast<NumberValue*>(lval.get()));
            NumberValue* nrval(dynamic_cast<NumberValue*>(lval.get()));
            if (nlval != 0 && nrval != 0) {
                NumberValue::CommonValueType res = 0;
                switch (_operator) {
                    case ADD: res = nlval->getCommonValue()
                                  + nrval->getCommonValue(); break;
                    case SUB: res = nlval->getCommonValue()
                                  - nrval->getCommonValue(); break;
                    case MUL: res = nlval->getCommonValue()
                                  * nrval->getCommonValue(); break;
                    case DIV: res = nlval->getCommonValue()
                                  / nrval->getCommonValue(); break;
                    case MOD: assert(0);
                }
                std::unique_ptr<Value> result(new FloatValue(res));
                out << "Performed float operation " << nlval << " "
                    << getOperatorName() << " " << nrval << " = " << *result
                    << "\n";
                return result;
            }
        }
        break;
        case MOD:
        {
            if (lval->getType() == Value::Integer &&
                rval->getType() == Value::Integer)
            {
                IntegerValue& ilval(static_cast<IntegerValue&>(*lval));
                IntegerValue& irval(static_cast<IntegerValue&>(*rval));
                std::unique_ptr<Value> result(new IntegerValue(
                            ilval.getValue() % irval.getValue(), false));
                out << "Performed integer operation " << ilval << " "
                    << getOperatorName() << " " << irval << " = " << *result
                    << "\n";
                return result;
            }
        }
        break;
    }
    out << "Failed to do operation " << getOperatorName()
        << " on values of type " << lval->getType() << " and "
        << rval->getType() << ". Resolving invalid.\n";
    return std::unique_ptr<Value>(new InvalidValue);
}
Example #11
0
std::unique_ptr<Value>
ArithmeticValueNode::getValue(std::unique_ptr<Value> lval,
                              std::unique_ptr<Value> rval) const
{
    switch (_operator) {
        case ADD:
        {
            if (lval->getType() == Value::String &&
                rval->getType() == Value::String)
            {
                StringValue& slval(static_cast<StringValue&>(*lval));
                StringValue& srval(static_cast<StringValue&>(*rval));
                return std::unique_ptr<Value>(new StringValue(
                            slval.getValue() + srval.getValue()));
            }
        }
        [[fallthrough]];
        case SUB:
        case MUL:
        case DIV:
        {
            if (lval->getType() == Value::Integer &&
                rval->getType() == Value::Integer)
            {
                IntegerValue& ilval(static_cast<IntegerValue&>(*lval));
                IntegerValue& irval(static_cast<IntegerValue&>(*rval));
                IntegerValue::ValueType res = 0;
                switch (_operator) {
                    case ADD: res = ilval.getValue() + irval.getValue(); break;
                    case SUB: res = ilval.getValue() - irval.getValue(); break;
                    case MUL: res = ilval.getValue() * irval.getValue(); break;
                    case DIV:
                        if (irval.getValue() != 0) {
                            res = ilval.getValue() / irval.getValue();
                        } else {
                            throw vespalib::IllegalArgumentException("Division by zero");
                        }
                        break;
                    case MOD: assert(0);
                }
                return std::unique_ptr<Value>(new IntegerValue(res, false));
            }
            NumberValue* nlval(dynamic_cast<NumberValue*>(lval.get()));
            NumberValue* nrval(dynamic_cast<NumberValue*>(rval.get()));
            if (nlval != 0 && nrval != 0) {
                NumberValue::CommonValueType res = 0;
                switch (_operator) {
                    case ADD: res = nlval->getCommonValue()
                                  + nrval->getCommonValue(); break;
                    case SUB: res = nlval->getCommonValue()
                                  - nrval->getCommonValue(); break;
                    case MUL: res = nlval->getCommonValue()
                                  * nrval->getCommonValue(); break;
                    case DIV:
                        if (nrval->getCommonValue() != 0) {
                            res = nlval->getCommonValue()
                                  / nrval->getCommonValue();
                        } else {
                            throw vespalib::IllegalArgumentException("Division by zero");
                        }
                        break;
                    case MOD: assert(0);
                }
                return std::unique_ptr<Value>(new FloatValue(res));
            }
        }
        break;
        case MOD:
        {
            if (lval->getType() == Value::Integer &&
                rval->getType() == Value::Integer)
            {
                IntegerValue& ilval(static_cast<IntegerValue&>(*lval));
                IntegerValue& irval(static_cast<IntegerValue&>(*rval));
                if (irval.getValue() != 0) {
                    return std::unique_ptr<Value>(new IntegerValue(ilval.getValue() % irval.getValue(), false));
                } else {
                    throw vespalib::IllegalArgumentException("Division by zero");
                }
            }
        }
        break;
    }
    return std::unique_ptr<Value>(new InvalidValue);
}
Example #12
0
std::unique_ptr<Value>
FunctionValueNode::traceValue(std::unique_ptr<Value> val,
                              std::ostream& out) const
{
    switch (val->getType()) {
        case Value::String:
        {
            StringValue& sval(static_cast<StringValue&>(*val));
            if (_function == LOWERCASE) {
                std::unique_ptr<Value> result(new StringValue(
                    vespalib::LowerCase::convert(sval.getValue())));
                out << "Performed lowercase function on '" << sval
                    << "' => '" << *result << "'.\n";
                return result;
            } else if (_function == HASH) {
                std::unique_ptr<Value> result(new IntegerValue(
                    hash(sval.getValue().c_str(), sval.getValue().size()),
                    false));
                out << "Performed hash on string '" << sval << "' -> "
                    << *result << "\n";
                return result;
            }
            break;
        }
        case Value::Float:
        {
            FloatValue& fval(static_cast<FloatValue&>(*val));
            if (_function == HASH) {
                FloatValue::ValueType ffval = fval.getValue();
                std::unique_ptr<Value> result(new IntegerValue(
                    hash(&ffval, sizeof(ffval)), false));
                out << "Performed hash on float " << ffval << " -> " << *result
                    << "\n";
                return result;
            } else if (_function == ABS) {
                FloatValue::ValueType ffval = fval.getValue();
                if (ffval < 0) ffval *= -1;
                out << "Performed abs on float " << fval.getValue() << " -> "
                    << ffval << "\n";
                return std::unique_ptr<Value>(new FloatValue(ffval));
            }
            break;
        }
        case Value::Integer:
        {
            IntegerValue& ival(static_cast<IntegerValue&>(*val));
            if (_function == HASH) {
                IntegerValue::ValueType iival = ival.getValue();
                std::unique_ptr<Value> result(new IntegerValue(
                    hash(&iival, sizeof(iival)), false));
                out << "Performed hash on float " << iival << " -> " << *result
                    << "\n";
                return result;
            } else if (_function == ABS) {
                IntegerValue::ValueType iival = ival.getValue();
                if (iival < 0) iival *= -1;
                out << "Performed abs on integer " << ival.getValue() << " -> "
                    << iival << "\n";
                return std::unique_ptr<Value>(new IntegerValue(iival, false));
            }
            break;
        }
        case Value::Bucket: break;
        case Value::Array: break;
        case Value::Struct: break;
        case Value::Invalid: break;
        case Value::Null: break;
    }
    out << "Cannot use function " << _function << " on a value of type "
        << val->getType() << ". Resolving invalid.\n";
    return std::unique_ptr<Value>(new InvalidValue);
}
Example #13
0
 At(std::unique_ptr<Expression> index_, std::unique_ptr<Expression> input_) :
     Expression(input_->getType().get<type::Array>().itemType),
     index(std::move(index_)),
     input(std::move(input_))
 {}