当前位置: 首页 > news >正文

教育行业网站建设vultr安装wordpress

教育行业网站建设,vultr安装wordpress,二级院系网站建设情况,个人可做网站需要什么材料文章目录 1 添加转大写字母输出功能2 责任链模式2.1 责任链的设计2.2 责任链的实现2.3 责任链的测试 3 代码重构3.1 类图设计3.2 重构设计 - 头文件3.3 重构实现 1 添加转大写字母输出功能 功能流程#xff1a; stdin通道类中包含一个功能处理类对象功能处理类中包含一个stdo… 文章目录 1 添加转大写字母输出功能2 责任链模式2.1 责任链的设计2.2 责任链的实现2.3 责任链的测试 3 代码重构3.1 类图设计3.2 重构设计 - 头文件3.3 重构实现 1 添加转大写字母输出功能 功能流程 stdin通道类中包含一个功能处理类对象功能处理类中包含一个stdout类对象数据被读取到stdin通道stdin通道将其交给功能处理类对象该对象判断数据特点后转大写或直接交个stdout类对象进行输出 class process_func { public:void DataProc(string _input){string output _input;transform(output.begin(), output.end(), output.begin(),::toupper);poOut-DataPush(output);} } *poProcess new process_func();/class stdin_channel :public Ichannel { public:// 通过 Ichannel 继承virtual bool ReadFd(std::string _input) override{cin _input;return true;}virtual bool WriteFd(std::string _output) override{return false;}virtual int GetFd() override{return 0;}virtual bool DataProcess(std::string _data) override{poProcess-DataProc(_data);return true;} };2 责任链模式 通道类和功能处理类的对象都是整个流程中的环节将这些环节连起来则形成责任链。 处理者类设计 提供handle函数作为链式处理的入口handle内部执行当前环节的处理并执行下一阶段的处理函数直到没有下一环节提供internalhandle纯虚函数用来执行本环节处理提供getnext纯虚函数用来获取下一环节 消息类设计 只提供虚析构函数用户可自行扩展 2.1 责任链的设计 /*责任链设计*/ class IZinxMsg { public:IZinxMsg() {}virtual ~IZinxMsg() {} };class AZinxHandler { public:AZinxHandler() {}virtual ~AZinxHandler() {}void Handle(IZinxMsg _oInput); protected:virtual IZinxMsg *InternelHandle(IZinxMsg _oInput) 0;virtual AZinxHandler *GetNextHandler(IZinxMsg _oNextMsg) 0; };2.2 责任链的实现 /*责任链实现*/ void AZinxHandler::Handle(IZinxMsg _oInput) {IZinxMsg *poNextMsg NULL;AZinxHandler *poNextHandler NULL;poNextMsg InternelHandle(_oInput);if (NULL ! poNextMsg){/*下一个环节处理*/poNextHandler GetNextHandler(*poNextMsg);/*有下一个环节才处理*/if (NULL ! poNextHandler){poNextHandler-Handle(*poNextMsg);}delete poNextMsg;}return; }2.3 责任链的测试 /*责任链测试将一串字符串交给处理者1进行首字母大写并输出然后转交给处理者2进行字符统计并输出*/ class str_msg :public IZinxMsg { public:str_msg(string _content):content(_content) {}string content; };class h2_Count :public AZinxHandler {// 通过 AZinxHandler 继承virtual IZinxMsg * InternelHandle(IZinxMsg _oInput) override{auto input dynamic_caststr_msg(_oInput);cout 处理者2处理开始 endl;cout input.content.size() endl;cout 处理者2处理结束 endl;return NULL;}virtual AZinxHandler * GetNextHandler(IZinxMsg _oNextMsg) override{return nullptr;} } h2;class h1_UpperFirst :public AZinxHandler {// 通过 AZinxHandler 继承virtual IZinxMsg * InternelHandle(IZinxMsg _oInput) override{auto input dynamic_caststr_msg(_oInput);cout 处理者1处理开始 endl;str_msg *pret new str_msg(input.content);auto head pret-content.begin();transform(head, head1, head, ::toupper);cout pret-content endl;cout 处理者1处理结束 endl;return pret;}virtual AZinxHandler * GetNextHandler(IZinxMsg _oNextMsg) override{return h2;} } h1;int main() {string input hello;str_msg input_msg(input);h1.Handle(input_msg); }3 代码重构 3.1 类图设计 3.2 重构设计 - 头文件 重构通道类和功能处理类继承handler类 通道类的data_process函数不要了通过重写internelhandle实现功能处理类的dataproc函数不要了通过重写internelhandle实现stdin类通过重写getnext方法返回功能处理对象功能处理类重写getnext方法返回stdout对象 重构kernel类 epoll中不再执行channel类的方法替换成handler类的handle方法kernel类判断当前epoll的触发方向并将其封装为消息类对象传递给通道类kernel增加函数用来处理程序向外发送数据取代直接调用通道类的sendout函数 创建消息类继承message类 创建IO方向类用来让epoll给channel对象传递当前ready的IO方向创建byte消息类用来让channel对象给功能处理对象传递待处理字符串逐级继承保证消息内容丰富性 /*重构类---设计*/#define GET_REF2DATA(type, ref, orig) type * pref dynamic_casttype *(orig); if (nullptr pref) {return nullptr;} type ref dynamic_casttype(orig)class IZinxMsg { public:IZinxMsg() {}virtual ~IZinxMsg() {} };class SysIOReadyMsg :public IZinxMsg { public:enum IO_DIC {IN, OUT} m_emIoDic;SysIOReadyMsg(IO_DIC _dic) :m_emIoDic(_dic) {} };class BytesMsg :public SysIOReadyMsg { public:BytesMsg(SysIOReadyMsg _base) :SysIOReadyMsg(_base.m_emIoDic) {}std::string szData; };//class AZinxHandler { public:AZinxHandler() {}virtual ~AZinxHandler() {}void Handle(IZinxMsg _oInput); protected:virtual IZinxMsg *InternelHandle(IZinxMsg _oInput) 0;virtual AZinxHandler *GetNextHandler(IZinxMsg _oNextMsg) 0; };class Ichannel:public AZinxHandler { public:virtual bool ReadFd(std::string _input) 0;virtual bool WriteFd(std::string _output) 0;virtual int GetFd() 0;void DataSendOut();void DataPush(std::string _data);std::liststd::string m_write_buffer;virtual IZinxMsg * InternelHandle(IZinxMsg _oInput) override; };class ZinxKernel {static void Zinx_SendOut(std::string _output, Ichannel _oChannel); };3.3 重构实现 /*重构实现*/ void ZinxKernel::Zinx_Run() {int iEpollRet -1;for(;;){struct epoll_event atmpEvent[100];iEpollRet epoll_wait(GetInstance()-iEpollFd, atmpEvent, 100, -1);if (-1 iEpollRet){if (EINTR errno){continue;}else{break;}}for (int i 0; i iEpollRet; i){Ichannel *poChannel static_castIchannel *(atmpEvent[i].data.ptr);if (0 ! (EPOLLIN atmpEvent[i].events)){string input;SysIOReadyMsg IoStat SysIOReadyMsg(SysIOReadyMsg::IN);poChannel-Handle(IoStat);}if (0 ! (EPOLLOUT atmpEvent[i].events)){poChannel-DataSendOut();if (poChannel-m_write_buffer.empty()){Zinx_ClearChannelOut(*poChannel);}}}} }void ZinxKernel::Zinx_SendOut(std::string _output, Ichannel _oChannel) {SysIOReadyMsg iodic SysIOReadyMsg(SysIOReadyMsg::OUT);BytesMsg oBytes BytesMsg(iodic);oBytes.szData _output;_oChannel.Handle(oBytes); }IZinxMsg * Ichannel::InternelHandle(IZinxMsg _oInput) {IZinxMsg *poRet NULL;GET_REF2DATA(SysIOReadyMsg, oIoStat, _oInput);if (oIoStat.m_emIoDic SysIOReadyMsg::IN){BytesMsg *poBytes new BytesMsg(oIoStat);if (true ReadFd(poBytes-szData)){poRet poBytes;}else{delete poBytes;}}else if (oIoStat.m_emIoDic SysIOReadyMsg::OUT){GET_REF2DATA(BytesMsg, oBytes, _oInput);if (true m_write_buffer.empty()){ZinxKernel::Zinx_SetChannelOut(*this);}m_write_buffer.push_back(oBytes.szData);}return poRet; }/*重构后测试*/ #include Zinx.h #include algorithm using namespace std;class stdout_channel :public Ichannel { public:virtual bool ReadFd(std::string _input) override{return false;}virtual bool WriteFd(std::string _output) override{cout _output endl;return true;}virtual int GetFd() override{return 1;}virtual AZinxHandler * GetNextHandler(IZinxMsg _oNextMsg) override{return nullptr;}} *poOut new stdout_channel();class process_func :public AZinxHandler{ public:void DataProc(string _input){string output _input;transform(output.begin(), output.end(), output.begin(),::toupper);poOut-DataPush(output);}virtual IZinxMsg * InternelHandle(IZinxMsg _oInput) override{GET_REF2DATA(BytesMsg, input, _oInput);string output input.szData;transform(output.begin(), output.end(), output.begin(), ::toupper);ZinxKernel::Zinx_SendOut(output, *poOut);return NULL;}virtual AZinxHandler * GetNextHandler(IZinxMsg _oNextMsg) override{return nullptr;} } *poProcess new process_func();class stdin_channel :public Ichannel { public:virtual bool ReadFd(std::string _input) override{cin _input;return true;}virtual bool WriteFd(std::string _output) override{return false;}virtual int GetFd() override{return 0;}virtual AZinxHandler * GetNextHandler(IZinxMsg _oNextMsg) override{return poProcess;}};int main() {ZinxKernel::ZinxKernelInit();ZinxKernel::Zinx_Add_Channel(*(new stdin_channel()));ZinxKernel::Zinx_Add_Channel(*poOut);ZinxKernel::Zinx_Run();ZinxKernel::ZinxKernelFini(); }
http://www.zqtcl.cn/news/407265/

相关文章:

  • 做电商图的设计网站蚌埠网页设计培训
  • 江苏省建设工程质量监督站网站手机网站 案例
  • 优而思 网站科技自立自强是国家强盛之基
  • 去哪里购买网站空间专门做家居的网站
  • 网站信息安全建设方案公众号网站建设
  • 网站的设计方案淘宝大数据查询平台
  • 深圳营销型网站建设 龙华信科网站项目有需要什么技术支持
  • 开源网站模板cms网店推广实训总结
  • 常见的电子商务网站有哪些建设校园门户网站信息意义
  • 象山经济开发区建设有限公司网站足球比赛直播app
  • 国外做mg动画的网站大全网站打不开 别的电脑能打开
  • 手机怎么创网站西宁企业做网站
  • 网站主机多大wordpress连接错误
  • 3d建站电商平台网站开发过程是什么
  • 优化核心系列网站wordpress下拉刷新
  • 深圳建站定制公司国外试用网站空间
  • 网站建设的原则有哪些内容建设网站的详细步骤
  • wordpress网站换字体宣传电脑的网站开发
  • 移动网站设计上机考试修改wordpress域名
  • 个体户 建设网站房子已交房 建设局网站查不到
  • 在自己的电脑建设空间网站百中搜优化软件
  • 专业房产网站建设公司wordpress导入项目
  • 网站安全建设必要性企业vi设计是什么意思
  • 建站工具有哪些社区兰州市城乡建设局网站通知公告
  • 深圳市移动端网站建设wordpress get_category_parents
  • 多用户商城(c2c)网站制作方案招聘网站如何做推广
  • 微信云网站用什么做做网站卖产品
  • 最专业的企业营销型网站建设简述无线网络优化的流程
  • 茶叶响应式网站做网站还有钱赚吗
  • 枣庄建设路小学网站资源下载wordpress