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

cad二次开发seo是什么意思如何实现

cad二次开发,seo是什么意思如何实现,网络公司给我们做的网站_但是我们不知道域名是否属于我们,赶集门户网站建设方案本文讨论的“文本单词查询复合表达式求值的实现”案例#xff0c;来自C primer第四版#xff0c;该案例面向对象编程和泛型编程#xff0c;涉及类的继承、抽象、多态、句柄、标准IO库、容器、算法库#xff0c;是综合性很强的程序 该程序实现文本中查找单个单词#xff0c…        本文讨论的“文本单词查询复合表达式求值的实现”案例来自C primer第四版该案例面向对象编程和泛型编程涉及类的继承、抽象、多态、句柄、标准IO库、容器、算法库是综合性很强的程序 该程序实现文本中查找单个单词“非”查询使用~操作符“或”查询使用|操作符“与”查询使用操作符组合查询如fiery bird | wind查询表达式求值 并 打印输出查询结果符合查询条件的文本共多少行、在查询本文的第几行、以及文本内容查询使用文本如下 Alice Emma has long flowing red hair. Her Daddy says when the wind blows through her hair, it looks almost alive, like a fiery bird in flight. A beautiful fiery bird, he tells her, magical but untamed. Daddy, shush, there is no such thing, she tells him, at the same time wanting him to tell her more. Shyly, she asks, I mean, Daddy, is there? 一、程序架构 创建标准IO库的ifstream对象infile定义的辅助函数openfile在命令行模式下用对象infile打开文本文件具体操作是在命令行下输入程序名字及文本文件所在目录 TextQuery类实现文本的读取存储容器vector按行存储文本容器map存储所有单词所在的行的set容器接口函数run_query返回一个单词所在的行的set容器text_line返回具体行的文本size返回存储的文本共多少行 句柄类Query包装类型为查询基类Query_base的模板句柄实例对象该句柄实例包装查询基类指针Query类对象由查询基类指针构造或string字符串由字符串构造的对象返回的是基类指针构造Query类对象的构造最终初始化查询基类指针注意查询基类指针指向具体的查询对象继承自查询基类Query_base的子类WordQuery、NotQuery、BinaryQueryBinaryQuery的子类AndQuery、OrQuery的对象 句柄类的友元函数是重载 |、、~操作符的函数返回句柄类对象动态构造的具体查询对象返回的是查询基类指针查询基类指针可以隐式转换为句柄类对象用以实现查询表达式 句柄类Query的接口函数display显式具体查询表达式接口函数eval返回符合查询条件的set容器存储所有符合查询条件的文本行 程序几个版本的演变及完整代码请点击这里本文讨论的是第六版 二、查询基类Query_base及其子类WordQuery、NotQuery、BinaryQueryBinaryQuery的子类AndQuery、OrQuery 查询基类Query_base代码 class Query_base{friend class Query; //句柄Queryfriend class HandleQuery_base ;//类型为Query_base的句柄模板实例 protected://派生类访问typedef TextQuery::line_no line_no;virtual ~Query_base() { } private: //两个接口用户和Query_base类的派生类只通过句柄Query使用Query_base类virtual std::setline_no eval(const TextQuery) const 0;virtual std::ostream display(std::ostream std::cout) const 0; }; 查询基类Query_base的子类WordQuery类的代码 class WordQuery: public Query_base{friend class Query;//句柄Query友元friend class HandleQuery_base ;WordQuery(const std::string s ):query_word(s ) { }std::setline_no eval(const TextQuery t)const{ //实现基类纯虚函数evalreturn t.run_query(query_word ); //用到了TextQuery类的成员函数run_query}std::ostream display(std::ostream os)const{ //实现基类纯虚函数displayreturn os query_word;}std::string query_word; //数据成员query_word }; 查询基类Query_base的子类NotQuery类的代码 class NotQuery: public Query_base{friend Query operator~(const Query );NotQuery(Query q ):query(q ) { } //构造std::setline_no eval(const TextQuery )const;std::ostream display(std::ostream os )const{return os ~( query ); //输出操作符的使用最终是对Query_base对象的虚函数的调用}const Query query; //数据成员Query句柄对象 }; std::setTextQuery::line_no NotQuery::eval(const TextQuery file) const{std::setTextQuery::line_no has_val query.eval(file );std::setline_no ret_lines;for(TextQuery::line_no n 0; n ! file.size(); n ){ if(has_val.find(n) has_val.end() ) //没找到就插入ret_lines.insert(n);}return ret_lines; } 查询基类Query_base的子类BinaryQuery类的代码 class BinaryQuery: public Query_base{ protected:BinaryQuery(Query left, Query right, std::string op ):lhs(left),rhs(right),oper(op) { }std::ostream display(std::ostream os)const{return os ( lhs oper rhs ); //输出操作符的使用最终是对Query_base对象的虚函数的调用}const Query lhs, rhs;const std::string oper; }; 查询基类Query_base的子类BinaryQuery类的子类AndQuery类的代码 class AndQuery: public BinaryQuery{friend Query operator(const Query , const Query );AndQuery(Query left, Query right ):BinaryQuery(left, right, ) { }std::setline_no eval(const TextQuery )const; }; std::setTextQuery::line_no AndQuery::eval(const TextQuery file) const{std::setline_no left lhs.eval(file ),right rhs.eval(file );std::setline_no ret_lines;set_intersection(left.begin(), left.end(),right.begin(),right.end(),inserter(ret_lines, ret_lines.begin()) );return ret_lines; } 算法std::set_intersection构造一个排序范围它是两个排序范围的集合交集实现运算 查询基类Query_base的子类BinaryQuery类的子类OrQuery类的代码 class OrQuery: public BinaryQuery{friend Query operator|(const Query , const Query );OrQuery(Query left, Query right ):BinaryQuery(left, right, | ) { }std::setline_no eval(const TextQuery )const; }; std::setTextQuery::line_no OrQuery::eval(const TextQuery file) const{std::setline_no right rhs.eval(file ),ret_lines lhs.eval(file ); //返回的set对象ret_lines初始化为lhs的结果ret_lines.insert(right.begin(), right.end() );return ret_lines; } 三、句柄模板 句柄简单的来讲它是一个类包装了一种基类指针的一个类该指针指向动态创建的有继承关系的对象句柄确保指针指向的对象在有指针指向的时候不会释放在没有指针指向的时候释放句柄避免了对象的重复创建句柄在C沉思录一书中有详细的描述可以点击这里查看 句柄模板类Handle代码 templateclass T class Handle{ private:T* ptr; //指向基础对象的指针size_t *use; //指针计数 //即多少个指针指向同一个基础对象void rem_ref(){ //删除基础对象(根据计数判断是否删除)if(--*use 0){delete ptr; //删除基础对象delete use; //删除计数}} public:Handle(T *p 0 ):ptr(p ),use(new size_t(1) ){ } //指针ptr指向动态分配的基础对象的地址//复制控制Handle(const Handle h):ptr(h.ptr ), use(h.use) { *use; } //复制*useHandle operator(const Handle rhs );~Handle() { rem_ref(); } //Handle对象析构 // 删除基础对象(根据计数判断是否删除)//用于访问基础对象const T operator*()const; //解引用操作符const T* operator-()const; //成员操作符 };templateclass T inline HandleT HandleT:: operator(const Handle rhs) {*rhs.use; //protect against self-assignment //防止自我复制rem_ref(); //decrement use count and delete pointers if neededptr rhs.ptr;use rhs.use;return *this; }templateclass T//const Handle对象可以调用返回类型是const T不可以修改基础对象 inline const T HandleT::operator*()const {if(ptr)return *ptr;throw std::runtime_error(dereference of unbound Handle); }templateclass T inline const T* HandleT::operator-()const {if(ptr)return ptr;throw std::runtime_error(dereference of unbound Handle); } 四、句柄类Query包装句柄模板实例对象 HandleQuery_base h的代码 class Query{ //使用Query友元的类增加句柄模板实例为友元friend Query operator~(const Query );friend Query operator|(const Query , const Query );friend Query operator(const Query , const Query ); public:Query(const std::string ); //!!! std::setTextQuery::line_no eval(const TextQuery t)const {return h-eval(t); } //!!!std::ostream display(std::ostream os std::cout) const {return h-display(os); }//!!! private:Query(Query_base *query):h(query) { } //!!!操作符创建Query对象调用HandleQuery_base h; //!!! }; Query::Query(const std::string s ):h(new WordQuery(s ) ) { } ; //!!!创建WordQuery对象 inline std::ostream operator (std::ostream os, const Query q){return q.display(os ); //参数q是const调用的display函数也必须是const }//return语句隐式调用接受Query_base指针的Query构造函数//隐式类型转换 inline Query operator(const Query lhs, const Query rhs){return new AndQuery(lhs, rhs ); } inline Query operator|(const Query lhs, const Query rhs){return new OrQuery(lhs, rhs ); } inline Query operator~(const Query oper){return new NotQuery(oper ); } 五、查询结果打印函数 void print_results(const std::setTextQuery::line_no locs, const std::string sought,const TextQuery file ) {typedef std::setTextQuery::line_no line_nums;line_nums::size_type size locs.size();std::cout \n sought occurs size make_plural(size, time, s ) std::endl;line_nums::const_iterator it locs.begin();for( ; it ! locs.end(); it ){std::cout \t(line (*it) 1 ) file.text_line(*it ) std::endl;} }std::string make_plural(std::size_t ctr, const std::string word,const std::string ending ) //make_plural //单词复数形式 {return (ctr 1 ) ? word : word ending; } 六、文件打开函数open_file std::ifstream open_file(std::ifstream in, const std::string file ) {in.close(); //如果已经打开in.clear();in.open(file.c_str() ); //打开文件return in; } 七、文本存储TextQuery类 class TextQuery{ public:typedef std::vectorstd::string::size_type line_no;void read_file(std::ifstream is){ //std::ifstream store_file(is);build_map();}std::setline_no run_query(const std::string )const;std::string text_line(line_no )const;line_no size() const{ return lines_of_text.size(); } //!!!const函数 private:void store_file(std::ifstream ); //std::ifstream //保存文件void build_map(); //从文件提取单词(去除标点符号)并记录单词所在文件的行号 std::vectorstd::string lines_of_text; std::map std::string, std::setline_no word_map;// };void TextQuery::store_file(std::ifstream is ) {std::string textline;while(getline(is,textline) ){lines_of_text.push_back(textline );} }void TextQuery::build_map() {for( line_no line_num 0; line_num ! lines_of_text.size();line_num ){std::istringstream line(lines_of_text[line_num] );//从std::vector读到 std::istringstreamstd::string word; while(line word ){word.std::string::erase( std::remove_if(word.begin(),word.end(), static_castint(*)(int) (ispunct)), word.end() );//!!!去除标点符号word_map[word].insert(line_num );}} }std::setTextQuery::line_no TextQuery::run_query(const std::string query_word )const {std::mapstd::string,std::setline_no ::const_iterator loc word_map.find(query_word ); //std::map里查找行std::setif(loc word_map.end() )return std::setline_no(); //没找到返回set空对象elsereturn loc-second; }std::string TextQuery::text_line(line_no line ) const {if(line lines_of_text.size() )return lines_of_text[line ];throw std::out_of_range(line number out of range); }
http://www.pierceye.com/news/210068/

相关文章:

  • 网站申请书博客系统做网站
  • 灰色行业老域名做网站不收录初学者的网站建设
  • 网站做成微信小程序贵州企业seo
  • 在淘宝做印刷网站怎么办wordpress 主题 edu
  • 成都设计公司网站线上线下一体化营销
  • 网站你懂我意思正能量晚上下载注册公司需要多少钱手续费
  • 在线html网站开发广州网站排名优化公司
  • 如何在免费网站上做推扩自己怎么来建设网站
  • 福安市教育局建设网站做架构图简单的网站
  • 如何快速进行网站开发seo是什么东西
  • 网站建设需要具备哪些学编程多少钱学费
  • 建设工程许可证在那个网站办金融行业网站制作
  • 邢台专业做网站价格信息流广告是什么
  • 网站开发的母的目的和意义.建设购物平台网站
  • 立方米网站建设做淘宝客网站用什么程序好
  • 怎样做网站挣钱建筑资料软件
  • 涿州建设局网站苏州市高新区建设局网站
  • 个人soho要怎么做企业网站成都包装设计公司
  • 网站开发 chrome浏览器崩溃ruhe用dw做网站
  • 全屏网站 图片优化个人网站cms系统
  • 做我女朋友程序网站邵东做网站
  • 建设网站如何挂到网上wordpress首页添加幻灯
  • 汕头正规网站建设模板总部城乡建设网站 资料员
  • vs 2017c 怎么建设网站网站建设的数字化和互联网化
  • 南昌网站设计公司海南营销网站建设
  • 购物网站素材个人搭建网站教程
  • 青岛网站建设哪里好模板建站服务公司
  • 青色网站欣赏wordpress中文购物
  • 建站培训全国住房与城乡建设部网站
  • 唐山网站建设方案策划沧州网站建设联系电话