对于Ciostream的自定义操纵器感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于AYCustomCameraiOS的自定义相机、c–Boostiostream:如何将ifstream转换为内
对于C iostream的自定义操纵器感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于AYCustomCamera iOS 的自定义相机、c – Boost iostream:如何将ifstream转换为内存映射文件?、c – iostream header vs iostream类、c – iostream的二进制版本的有用信息。
本文目录一览:- C iostream的自定义操纵器
- AYCustomCamera iOS 的自定义相机
- c – Boost iostream:如何将ifstream转换为内存映射文件?
- c – iostream header vs iostream类
- c – iostream的二进制版本
C iostream的自定义操纵器
std::ostringstream os; std::string name("Joe"); os << "SELECT * FROM customers WHERE name = " << quote << name;
操纵者引用将引用名称以产生:
SELECT * FROM customers WHERE name = 'Joe'
我该如何完成呢?
谢谢.
解决方法
使用std命名空间中定义的运算符输出字符串.如果要更改打印方式,同时保持操纵器的外观,可以创建代理类:
namespace quoting { struct quoting_proxy { explicit quoting_proxy(std::ostream & os):os(os){} template<typename Rhs> friend std::ostream & operator<<(quoting_proxy const& q,Rhs const& rhs) { return q.os << rhs; } friend std::ostream & operator<<(quoting_proxy const& q,std::string const& rhs) { return q.os << "'" << rhs << "'"; } friend std::ostream & operator<<(quoting_proxy const& q,char const* rhs) { return q.os << "'" << rhs << "'"; } private: std::ostream & os; }; struct quoting_creator { } quote; quoting_proxy operator<<(std::ostream & os,quoting_creator) { return quoting_proxy(os); } } int main() { std::cout << quoting::quote << "hello" << std::endl; }
哪个适合用于ostream.如果要进行概括,可以将其设为模板,也可以接受basic_stream而不是普通字符串.在某些情况下,它与标准操纵器有不同的行为.因为它通过返回代理对象来工作,所以它不适用于像
std::cout << quoting::quote; std::cout << "hello";
AYCustomCamera iOS 的自定义相机
AYCustomCamera 介绍
Apple 自带的相机不支持全屏拍摄,该 demo 主要为了实现全屏拍摄。
自定义照相机
由于 UIImagePicker 调用照相机拍照无法拍摄全屏照片,于是基于 AVFoundation 框架封装了简易照相机。
支持闪光灯,前后摄像头切换,手指拖放放大
使用简单,仅需实例化对象,实现代理方法、模态跳转即可。
运行效果:
AYCustomCamera 官网
https://git.oschina.net/AngeloTsui/AYCustomCamera
c – Boost iostream:如何将ifstream转换为内存映射文件?
所以我尝试这样的代码:
#include <iostream> #include <boost/iostreams/device/mapped_file.hpp> #include <boost/iostreams/stream.hpp> using namespace boost::iostreams; int main(int argc,char **argv) { stream <mapped_file_sink> out; try { mapped_file_params p("one.txt"); p.new_file_size = 1024 * sizeof (char); out.open(mapped_file_sink(p),std::ios_base::out | std::ios_base::binary); } catch (const std::exception &e) { std::cout << e.what() << std::endl; return 2; } std::cin.get(); return 0; }
所以它打开或创建文件,把它放入ram.但是我无法访问它(我无法编辑并保存但我可以打开)来自任何其他程序=(如何使文件可以从其他程序编辑?
解决方法
总结
以上是小编为你收集整理的c – Boost iostream:如何将ifstream转换为内存映射文件?全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
c – iostream header vs iostream类
但是,我没有看到iostream头文件和iostream类之间的这种关系. iostream头文件只声明了一些外部变量,但它们似乎都没有直接与iostream类有任何关系. iostream类似乎也没有声明任何新函数.为什么我们有iostream类和iostream头文件?抱歉,如果我听起来很困惑,但这些东西真让我困惑.
解决方法
std :: iostream是模板类std :: basic_iostream的typedef(具体来说,对于basic_iostream< char>).在我的平台上,< iostream>包括< istream>它定义了basic_iostream,以及< iosfwd>其中包含typedef.
c – iostream的二进制版本
my_file << binary::u32le << my_int << binary::u16le << my_string;
将my_int写为无符号的32位整数,将my_string写为长度前缀的字符串(前缀为u16le.)要读回文件,可以翻转箭头.效果很好.然而,我在设计上遇到了一个障碍,我仍然围着它.所以,是时候问问了. (我们做了一些假设,例如8位字节,2s补码整数和IEEE浮点数.)
引擎盖下的iostream使用streambufs.这真是一个非常棒的设计 – iostream将’int’的序列化编码到文本中,并让底层的streambuf处理其余部分.因此,你得到了cout,fstreams,stringstreams等.所有这些,包括iostream和streambufs,都是模板化的,通常是在char上,但有时也作为wchar.但是,我的数据是一个字节流,最好用’unsigned char’表示.
我的第一次尝试是基于unsigned char来模拟类. std :: basic_string模板足够好,但streambuf没有.我遇到了一个名为codecvt的类的几个问题,我永远无法遵循unsigned char主题.这提出了两个问题:
1)为什么streambuf对此类事情负责?似乎代码转换不属于streambuf的职责 – streambufs应该采取流,并缓冲数据到/从它缓冲数据.而已.像代码转换一样高级的东西感觉它应该属于iostreams.
由于我无法使用模板化的streambuf来处理unsigned char,所以我回到char,只是在char / unsigned char之间传递数据.出于显而易见的原因,我试图尽量减少演员阵容.大多数数据基本上都是在read()或write()函数中结束,然后调用底层的streambuf. (并在此过程中使用强制转换.)读取功能基本上是:
size_t read(unsigned char *buffer,size_t size) { size_t ret; ret = stream()->sgetn(reinterpret_cast<char *>(buffer),size); // deal with ret for return size,eof,errors,etc. ... }
好的解决方案,糟糕的解
前两个问题表明需要更多信息.首先,查看了boost :: serialization等项目,但它们存在于更高级别,因为它们定义了自己的二进制格式.这更适用于较低级别的读/写,其中希望定义格式,或者已经定义了格式,或者不需要或不需要批量元数据.
其次,有人问过binary :: u32le修饰符.它是一个类的实例化,它具有所需的字节顺序和宽度,此刻可能是未来的签名.该流保存该类的最后传递的实例的副本,并在序列化中使用该副本.这是一个解决方法,我试图重载<<运算符因此:
bostream &operator << (uint8_t n); bostream &operator << (uint16_t n); bostream &operator << (uint32_t n); bostream &operator << (uint64_t n);
但当时,这似乎不起作用.我有一些模糊函数调用的问题.对于常数来说尤其如此,尽管你可以像一张海报建议的那样,将其演绎或仅仅声明为const< type>.我似乎记得有一些其他更大的问题.
解决方法
我的解决方案(只需要在一台机器上临时序列化数据,因此不需要解决字节顺序)基于这种模式:
// deducible template argument read template <class T> void read_raw(std::istream& stream,T& value,typename boost::enable_if< boost::is_pod<T> >::type* dummy = 0) { stream.read(reinterpret_cast<char*>(&value),sizeof(value)); } // explicit template argument read template <class T> T read_raw(std::istream& stream) { T value; read_raw(stream,value); return value; } template <class T> void write_raw(std::ostream& stream,const T& value,typename boost::enable_if< boost::is_pod<T> >::type* dummy = 0) { stream.write(reinterpret_cast<const char*>(&value),sizeof(value)); }
然后,我进一步为任何非POD类型(例如字符串)重载了read_raw / write_raw.请注意,只需要重载read_raw的第一个版本;如果您是use ADL correctly,则第二个(1-arg)版本可以调用稍后定义的2-arg重载以及其他名称空间.
写例子:
int32_t x; int64_t y; int8_t z; write_raw(is,x); write_raw(is,y); write_raw<int16_t>(is,z); // explicitly write int8_t as int16_t
阅读示例:
int32_t x = read_raw<int32_t>(is); // explicit form int64_t y; read_raw(is,y); // implicit form int8_t z = numeric_cast<int8_t>(read_raw<int16_t>(is));
它不像重载运算符那样性感,并且事情不容易在一条线上(我倾向于避免,因为调试断点是面向行的),但我认为它变得更简单,更明显,并且不多更冗长.
我们今天的关于C iostream的自定义操纵器的分享就到这里,谢谢您的阅读,如果想了解更多关于AYCustomCamera iOS 的自定义相机、c – Boost iostream:如何将ifstream转换为内存映射文件?、c – iostream header vs iostream类、c – iostream的二进制版本的相关信息,可以在本站进行搜索。
本文标签: