示例#1
0
void java_lang_String::getChars(jint srcBegin, jint srcEnd, Unicod_ap dst, jint dstBegin) {
	if (srcBegin < 0) {
	    THROW_EX_NEW$(java_lang_StringIndexOutOfBoundsException, (srcBegin));
	} 
	if (srcEnd > this->m_count) {
		THROW_EX_NEW$(java_lang_StringIndexOutOfBoundsException, (srcEnd));
	} 
	if (srcBegin > srcEnd) {
		THROW_EX_NEW$(java_lang_StringIndexOutOfBoundsException, (srcEnd - srcBegin));
	}
	
	if (dst == FASTIVA_NULL) {
		fastiva_throwNullPointerException();
	}
	
	int copyLen = (srcEnd - srcBegin);
	if (copyLen == 0) {
		return;
	}

	if (dst->length() - dstBegin < copyLen) {
		fastiva_throwArrayStoreException();
	}
	
	Unicod_A::Buffer dst_buf(dst, dstBegin, copyLen);
	unicod *pDest = dst_buf;
	srcBegin += this->m_offset;
	Unicod_A::Buffer src_buf(this->m_value, srcBegin, copyLen);
	unicod *pSrc = src_buf;
	memcpy(pDest, pSrc, copyLen*sizeof(unicod));
}
示例#2
0
文件: Dip3.cpp 项目: easten20/DIP
/*
src:    input image
kernel:  filter kernel
return:  convolution result
*/
Mat Dip3::spatialConvolution(Mat& src, Mat& kernel){
	
	Mat outputImage = src.clone();
	int border = kernel.cols / 2; //assume it is symmetry		
	Mat src_buf(src.rows + border*2, src.cols + border*2, src.depth()); //prepare for matrix with border
	copyMakeBorder(src, src_buf, border, border,border, border, BORDER_REPLICATE); //extend border by replicating rows and cols
	//flip kernel along x and y axis
	flip(kernel, kernel, -1);
	for (int y = border; y < src_buf.rows-border; y++){
		for (int x = border; x < src_buf.cols-border; x++){
			float convolution = 0.;
			for (int j = 0; j < kernel.rows; j++){
				for (int i = 0; i < kernel.cols; i++){
					convolution += src_buf.at<float>(y - (kernel.rows/2) + j, x - (kernel.cols/2) + i)*kernel.at<float>(j, i);
				}
			}
			outputImage.at<float>(y-border, x-border) = convolution;
		}
	}
	return outputImage;
}
示例#3
0
文件: CommandCopy.cpp 项目: unoyx/vfs
int CommandCopy::copyFile(MyString src, MyString dst, VirtualDiskNode* vfs)
{
    HANDLE src_file = CreateFile(src.c_str(),
                                 GENERIC_READ,
                                 FILE_SHARE_READ,
                                 nullptr,
                                 OPEN_EXISTING,
                                 FILE_ATTRIBUTE_NORMAL,
                                 nullptr);
    if (src_file == INVALID_HANDLE_VALUE) 
    {
        throw CommandException(_T("系统找不到指定的文件\n"));
    }
    DWORD file_size = GetFileSize(src_file, nullptr);
    //CHAR *src_buf = new CHAR[file_size];
    DelegateMem<char> src_buf(new char[file_size]);
    DWORD read_bytes = 0;
    if (!ReadFile(src_file, 
                  src_buf,
                  file_size,
                  &read_bytes,
                  nullptr)
        || file_size != read_bytes)
    {
        //delete[] src_buf;
        CloseHandle(src_file);
        throw CommandException(src + _T("文件读取失败\n"));
    }

    FileHandler dst_file(nullptr);
    if (vfs->isFile(dst))
    {
        _tprintf(_T("覆盖文件%s,是否确认<Y/N>?"), basename(dst).c_str());
        TCHAR confirm = 0;
        _tscanf_s(_T("%c%*c"), &confirm, sizeof(confirm));
        if (confirm != 'y' && confirm != 'Y')
        {
            return 0;
        }
        dst_file = vfs->openFile(dst);
        if (!dst_file.isValid())
        {
            //delete[] src_buf;
            CloseHandle(src_file);
            throw CommandException(_T("无法打开/创建目标文件\n"));
        }
    }
    else
    {
        dst_file = vfs->createFile(dst);
        if (!dst_file.isValid())
        {
            CloseHandle(src_file);
            throw CommandException(_T("无法打开/创建目标文件\n"));
        }
    }
    // TODO : 文件写入
    dst_file.write(src_buf, file_size);
    //delete[] src_file;
    CloseHandle(src_file);
    return 0;
}
示例#4
0
void java_lang_System_C$::arraycopy(
	java_lang_Object_p src0, 
	jint srcPos, 
	java_lang_Object_p dst0, 
	jint dstPos, 
	jint length
) {
	CHECK_STACK_FAST();

	// @1. Null-Pointer 검사
	java_lang_Class_p dstClass = dst0->getClass$();
	java_lang_Class_p srcClass = src0->getClass$();
	int dstDepth = fm::getArrayDimension(dstClass);
	int srcDepth = fm::getArrayDimension(srcClass);

	KASSERT(dstDepth <= FASTIVA_MAX_ARRAY_DIMENSION);
	KASSERT(srcDepth <= FASTIVA_MAX_ARRAY_DIMENSION);

	// @2. Array 여부 검사 (src0나 dst0가 Interface인 경우엔 depth가 0)
	if (dstDepth <= 0 || srcDepth <= 0) {
		dstDepth = fm::getArrayDimension(dstClass);
		srcDepth = fm::getArrayDimension(srcClass);
throw_array_store_exception:
		fastiva_throwArrayStoreException();
	}

	java_lang_Object_ap dst = (java_lang_Object_ap)dst0;
	java_lang_Object_ap src = (java_lang_Object_ap)src0;

	// @3. Index 검사 
    uint srcEnd = length + srcPos;
    uint dstEnd = length + dstPos;

    if ((length < 0) || (srcPos < 0) || (dstPos < 0)
	||  (srcEnd > (uint)src->length())
	||  (dstEnd > (uint)dst->length())) {
		fastiva.throwArrayIndexOutOfBoundsException();
        return;
    }

	// @4. 길이가 0인가 검사.
	if (length == 0) {
		return;
	}

	
	const fastiva_ClassContext* dstContext = dstClass->m_pContext$;
	const fastiva_ClassContext* srcContext = srcClass->m_pContext$;

	//typedef FOX_PTR<java_lang_Object, false> ITEM_PTR;
	Int_A::Buffer src_buf((Int_ap)src); // 실제론 int array가 아니다.
	java_lang_Object_p* ppItemDst = (java_lang_Object_p*)fm::getUnsafeBuffer(dst); // dst는 계속 사용된다.
	java_lang_Object_p* ppItemSrc = (java_lang_Object_p*)(jint*)src_buf;
	java_lang_Object_p pItem;

	// @5. Primitive Array 처리
	if (srcContext->isPrimitive()) {
		srcDepth --;
	}
	if (dstContext->isPrimitive()) {
		dstDepth --;
	}
	
	if (srcDepth == 0 || dstDepth == 0) {
		if (srcContext != dstContext || dstDepth != srcDepth) {
	        goto throw_array_store_exception;
		}

        /* We've already determined that src and dst are primitives of the
         * same type */
        int itemSize = fm::getPrimitiveArrayItemSize(srcContext);
		char * ddd = (char*)(void*)ppItemDst;
		char * sss = (char*)(void*)ppItemSrc;
        ::memmove(&ddd[dstPos * itemSize],
                &sss[srcPos * itemSize],
                itemSize * length);
		return;
    }

	int isObjectArrayTarget;
	int isObjectArraySource;
	//bool isInterfaceDst = !dstContext->isInstance();
	const int increement = sizeof(void*);
	ppItemDst += dstPos;
	ppItemSrc += srcPos;

	if (dst == src) {
		if (ppItemDst < ppItemSrc) {
			goto copy_array_region;
		}

		length -= 1;
		ppItemDst += length;
		ppItemSrc += length;
		while (length -- >= 0) {
			dst->setField_$$(*ppItemSrc, ppItemDst);
			ppItemDst --;
			ppItemSrc --;
		}
		return;
	}

	if (dstDepth == srcDepth) {
		if (dstContext == srcContext || dstContext->isAssignableFrom(srcContext)) {
			goto copy_array_region;
		}
	}

	isObjectArrayTarget = (dstContext == java_lang_Object_T$::getRawContext$()) ? 1 : 0;
	if (isObjectArrayTarget 
	&&  dstDepth <= srcDepth) {
		goto copy_array_region;
	}

	// @6. FASTIVA_NULL을 무조건 처리
	while (*ppItemSrc == FASTIVA_NULL) {
		dst->setField_$$((java_lang_Object_p)FASTIVA_NULL, ppItemDst);
		if (--length == 0) {
			return;
		}
		ppItemSrc ++;
		ppItemDst ++;
	}
	//*/
	isObjectArraySource = (srcContext == java_lang_Object_T$::getRawContext$()) ? 1 : 0;

//#define NEXT_ARRAY_ITEM_PTR(ppItem)	(ppItem = (java_lang_Object_p*)((char*)ppItem + increement))
	// @7. FASTIVA_NULL이 아닌 item의 처리
	if (isObjectArraySource) {
		KASSERT(!isObjectArrayTarget || dstDepth > srcDepth);
		if (dstDepth < srcDepth) {
			// Target 이 Object인 경우는 이미 검사되었다.
	        goto throw_array_store_exception;
		}

		if (isObjectArrayTarget) {
			for (; length-- > 0; ) {
				pItem = *ppItemSrc++;
				if (pItem != FASTIVA_NULL) {
					java_lang_Class_p pItemClass = pItem->getClass();
					if (fm::getArrayDimension_asObjectArray(pItemClass) < dstDepth) {
						goto throw_array_store_exception;
					}
				}
				// Pure Object Array 의 모든 item은 Pure-Instance이다.
				dst->setField_$$(pItem, ppItemDst);
				ppItemDst ++;
			}
		}
		else {
			int itemDepth = dstDepth - 1;
			for (; length-- > 0; ) {
				pItem = *ppItemSrc++;
				if (pItem != FASTIVA_NULL) {
					java_lang_Class_p pItemClass = pItem->getClass();
					if (fm::getArrayDimension_asObjectArray(pItemClass) != itemDepth) {
						goto throw_array_store_exception;
					}
					const fastiva_ClassContext* pItemContext = pItemClass->m_pContext$;
					if (dstContext != pItemContext
					&&	!dstContext->isAssignableFrom(pItemContext)) {
						goto throw_array_store_exception;
					}
				}
				dst->setField_$$(pItem, ppItemDst);
				ppItemDst ++;
			}
		}
		return;
	}
	else {
		KASSERT(!isObjectArrayTarget || dstDepth > srcDepth);
		if (dstDepth != srcDepth) {
			goto throw_array_store_exception;
		}
		KASSERT(!isObjectArrayTarget);
		KASSERT(!dstContext->isAssignableFrom(srcContext));

		int itemDepth = dstDepth - 1;
		for (; length-- > 0; ) {
			pItem = *ppItemSrc++;
			if (pItem != FASTIVA_NULL) {
				const fastiva_ClassContext* pItemContext = pItem->getClass$()->m_pContext$;
				if (dstContext != pItemContext
				&&	!dstContext->isAssignableFrom(pItemContext)) {
					goto throw_array_store_exception;
				}
			}
			dst->setField_$$(pItem, ppItemDst);
			ppItemDst ++;
		}
		return;
	}

copy_array_region:
	while (length -- > 0) {
		dst->setField_$$(*ppItemSrc, ppItemDst);
		ppItemDst ++;
		ppItemSrc ++;
	}
	return;
}