当前位置: 首页>>代码示例>>C++>>正文


C++ FileName::getFile方法代码示例

本文整理汇总了C++中FileName::getFile方法的典型用法代码示例。如果您正苦于以下问题:C++ FileName::getFile方法的具体用法?C++ FileName::getFile怎么用?C++ FileName::getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileName的用法示例。


在下文中一共展示了FileName::getFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getPortInfo

static PortInfo getPortInfo(const FileName & filename){
	PortInfo info;
	
	const auto parts = split(filename.getFile(),':');
	
	info.portName  = parts.empty() ? "" : parts[0];
#ifdef _WIN32
	info.internalPortName =  "\\\\.\\" + info.portName;
#else
	info.internalPortName = info.portName;
#endif
	info.baudRate = 9600;
	info.bytesize = serial::eightbits;
	info.stopbits = serial::stopbits_one;
	info.flowcontrol = serial::flowcontrol_none;
	info.parity = serial::parity_none;
for(auto& s:parts)
//	std::cout << ">"<<s<<"\n";

	if(parts.size()>1){
		info.baudRate = StringUtils::toNumber<uint32_t>(parts[1]);
		if(parts.size()>2){
			switch(StringUtils::toNumber<uint32_t>(parts[2])){
				case 5:	info.bytesize = serial::fivebits;	break;
				case 6:	info.bytesize = serial::sixbits;	break;
				case 7:	info.bytesize = serial::sevenbits;	break;
				case 0:// empty -> default
				case 8:	info.bytesize = serial::eightbits;	break;
				default:
					throw std::invalid_argument("SerialProvider: invalid bytesize :"+filename.toString());
			}
			if(parts.size()<=3 || parts[3].empty() || parts[3]=="n"){
				info.parity = serial::parity_none;
			}else if(parts[3]=="o"){
				info.parity = serial::parity_odd;
			}else if(parts[3]=="e"){
				info.parity = serial::parity_even;
			}else{
				throw std::invalid_argument("SerialProvider: invalid parity :"+filename.toString());
			}
			if(parts.size()<=4 || parts[4].empty() || parts[4]=="1"){
				info.stopbits = serial::stopbits_one;
			}else if(parts[4]=="2"){
				info.stopbits = serial::stopbits_two;
			}else{
				throw std::invalid_argument("SerialProvider: invalid stopbits :"+filename.toString());
			}
			if(parts.size()<=5 || parts[5].empty() || parts[5]=="n"){
				info.flowcontrol = serial::flowcontrol_none;
			}else if(parts[5]=="h"){
				info.flowcontrol = serial::flowcontrol_hardware;
			}else if(parts[5]=="s"){
				info.flowcontrol = serial::flowcontrol_software;
			}else{
				throw std::invalid_argument("SerialProvider: invalid flowcontrol :"+filename.toString());
			}
		}
	}
	return info;
}
开发者ID:PADrend,项目名称:Util,代码行数:60,代码来源:SerialProvider.cpp

示例2:

AbstractFSProvider::status_t ZIPProvider::ZIPHandle::writeFile(const FileName & file, const std::vector<uint8_t> & data, bool overwrite) {
	if (file.getFile().empty()) {
		return FAILURE;
	}

	bool replace = false;

	int index = zip_name_locate(handle, file.getPath().c_str(), 0);
	if (index != -1) {
		// File already exists.
		if (!overwrite) {
			return FAILURE;
		} else {
			replace = true;
		}
	}

	// Store data temporary because libzip writes data not until zip_close.
	tempStore.emplace_back(data);

	zip_source * source = zip_source_buffer(handle,
			tempStore.back().data(), static_cast<off_t>(tempStore.back().size()), 0);
	if (source == nullptr) {
		WARN(zip_strerror(handle));
		zip_source_free(source);
		tempStore.pop_back();
		return FAILURE;
	}

	int newIndex;
	if (replace) {
		newIndex = zip_replace(handle, index, source);
	} else {
		newIndex = zip_add(handle, file.getPath().c_str(), source);
	}
	if (newIndex == -1) {
		WARN(zip_strerror(handle));
		zip_source_free(source);
		tempStore.pop_back();
		return FAILURE;
	}
	dataWritten = true;
	return OK;
}
开发者ID:PADrend,项目名称:Util,代码行数:44,代码来源:ZIPProvider.cpp

示例3: fileSize

AbstractFSProvider::status_t ZIPProvider::ZIPHandle::readFile(const FileName & file, std::vector<uint8_t> & data) {
	if (file.getFile().empty()) {
		return FAILURE;
	}

	const size_t size = fileSize(file);
	if (size == 0) {
		return FAILURE;
	}

	zip_file * fileHandle = zip_fopen(handle, file.getPath().c_str(), 0);
	if (fileHandle == nullptr) {
		WARN(zip_strerror(handle));
		return FAILURE;
	}

	data.resize(size);
	const int bytesRead = zip_fread(fileHandle, data.data(), data.size());
	if (bytesRead == -1) {
		WARN(zip_strerror(handle));
		zip_fclose(fileHandle);
		return FAILURE;
	}
	if (static_cast<size_t>(bytesRead) != size) {
		WARN("Sizes differ during read.");
		zip_fclose(fileHandle);
		return FAILURE;
	}

	if (zip_fclose(fileHandle) == -1) {
		WARN(zip_strerror(handle));
		return FAILURE;
	}

	return OK;
}
开发者ID:PADrend,项目名称:Util,代码行数:36,代码来源:ZIPProvider.cpp


注:本文中的FileName::getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。