Пример #1
0
	bool File::write(std::shared_ptr<Data> data)
	{
		if (good() && !isRead() && isBinary())
		{
			handle.write(reinterpret_cast<char *>(data->getBuffer()), data->getSize());
		}
		return false;
	}
Пример #2
0
	bool File::write(const std::string &line)
	{
		if (good() && !isRead() && !isBinary())
		{
			handle << line << std::endl;
		}
		return false;
	}
Пример #3
0
	bool File::read(std::string &line)
	{
		if (good() && isRead() && !isBinary() && !eof())
		{
			std::getline(handle, line);
			return true;
		}
		return false;
	}
Пример #4
0
	size_t File::getSize()
	{
		if (good() && isRead())
		{
			auto pos = handle.tellg();
			handle.seekg(0, std::ios::beg);
			auto begin = handle.tellg();
			handle.seekg(0, std::ios::end);
			auto end = handle.tellg();
			handle.seekg(pos);
			return static_cast<size_t>(end - begin);
		}
		return 0;
	}
Пример #5
0
Modbus_RTU::Modbus_RTU(QObject *parent,AbstractSerial *port):
        QObject(parent)
{
    this->port=port;

    in_thread=new Input_Thread(this,port);
    out_thread=new Output_Thread(this,port);
    connect(in_thread,SIGNAL(isRead(QByteArray)),this,SLOT(ResponseHandling(QByteArray)));
    in_thread->start();


    connect(this,SIGNAL(WriteToOut_Thread(QByteArray)),out_thread,SLOT(Send(QByteArray)));
    out_thread->start();

    timer=new QTimer(this);

    connect(timer,SIGNAL(timeout()),this,SIGNAL(DEVICE_NOT_CONNECTED()));
}
Пример #6
0
	std::shared_ptr<FileData> File::read(FileReadMode readMode, size_t size)
	{
		std::shared_ptr<FileData> out = nullptr;
		if (good() && isRead() && isBinary())
		{
			if (readMode == FileReadMode::BLOCK)
			{
				size = std::min(size, available());
			}
			else if (readMode == FileReadMode::ALL)
			{
				size = available();
			}
			out = std::make_shared<FileData>(size, filename);
			handle.read(reinterpret_cast<char *>(out->getBuffer()), size);
		}
		return out;
	}
Пример #7
0
bool isSubTypeOf(const TypePtr& subType, const TypePtr& superType) {

	// quick check - reflexivity
	if (*subType == *superType) {
		return true;
	}

	// check for recursive types
	if (subType->getNodeType() == NT_RecType || superType->getNodeType() == NT_RecType) {

		// since they are not equivalent we have to compare the unrolled version of the sub with the super type
		if (subType->getNodeType() == NT_RecType) {
			return isSubTypeOf(subType.as<RecTypePtr>()->unroll(), superType);
		}

		if (superType->getNodeType() == NT_RecType) {
			assert(subType->getNodeType() != NT_RecType);
			return isSubTypeOf(subType, superType.as<RecTypePtr>()->unroll());
		}

		assert(false && "How could you get here?");
	}

	// check whether the sub-type is generic
	if (subType->getNodeType() == NT_GenericType || subType->getNodeType() == NT_StructType) {
		// use the delta algorithm for computing all the super-types of the given sub-type
		return isSubTypeOfInternal(subType, superType);
	}

	// check for vector types
	if (subType.isa<VectorTypePtr>() ) {
		VectorTypePtr vector = static_pointer_cast<const VectorType>(subType);
		// potential super type is an array of the same element type
		IRBuilder builder(vector->getNodeManager());
		return *superType == *builder.arrayType(vector->getElementType());
	}

	// for all other relations, the node type has to be the same
	if (subType->getNodeType() != superType->getNodeType()) {
		return false;
	}

	// check function types
	if (subType->getNodeType() == NT_FunctionType) {
		FunctionTypePtr funTypeA = static_pointer_cast<const FunctionType>(subType);
		FunctionTypePtr funTypeB = static_pointer_cast<const FunctionType>(superType);

		// check kind of functions
		if (funTypeA->getKind() != funTypeB->getKind()) {
			// only closure to plain conversion is allowed
			if (!(funTypeB->isClosure() && funTypeA->isPlain())) {
				return false;
			}
		}

		bool res = true;
		res = res && funTypeA->getParameterTypes().size() == funTypeB->getParameterTypes().size();
		res = res && isSubTypeOf(funTypeA->getReturnType(), funTypeB->getReturnType());
		for(std::size_t i = 0; res && i<funTypeB->getParameterTypes().size(); i++) {
			res = res && isSubTypeOf(funTypeB->getParameterTypes()[i], funTypeA->getParameterTypes()[i]);
		}
		return res;
	}

	// check reference types
	if (subType->getNodeType() == NT_RefType) {
		const auto& basic = subType->getNodeManager().getLangBasic();

		// check source / sink
		auto srcRef = subType.as<RefTypePtr>();
		auto trgRef = superType.as<RefTypePtr>();

		// check read/write privileges
		if (trgRef.isRead() && !srcRef.isRead()) return false;
		if (trgRef.isWrite() && !srcRef.isWrite()) return false;

		// check element type
		auto srcElement = subType.as<RefTypePtr>()->getElementType();
		auto trgElement = superType.as<RefTypePtr>()->getElementType();

		// if element types are identical => it is fine
		//if (srcElement == trgElement) return true;
		if(core::analysis::compareTypes(srcElement, trgElement)) return true;

		// if sub-type is ref<any> it is ok
		if (basic.isAny(trgElement)) {
			return true;
		}

		// support nested references
		if (srcElement.isa<RefTypePtr>() && trgElement.isa<RefTypePtr>()) {
			return isSubTypeOf(srcElement, trgElement);
		}

		// a ref<vector<X,Y>> is a sub-type of a ref<array<X,1>>
		if (trgElement.isa<ArrayTypePtr>() && srcElement.isa<VectorTypePtr>()) {
			IRBuilder builder(srcElement.getNodeManager());
			auto one = builder.concreteIntTypeParam(1);

			// array needs to be 1-dimensional and both have to have the same element type
			return trgElement.as<ArrayTypePtr>()->getDimension() == one &&
				   trgElement.as<ArrayTypePtr>()->getElementType() == srcElement.as<VectorTypePtr>()->getElementType();
		}

		// also support references of derived classes being passed to base-type pointer
		if (core::analysis::isObjectType(srcElement) && core::analysis::isObjectType(trgElement)) {
			if (isSubTypeOf(srcElement, trgElement)) {
				return true;
			}
		}

	}

	// no other relations are supported
	return false;
}