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


C++ stringstream::ignore方法代码示例

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


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

示例1: getRule

    unsigned int getRule(stringstream& ss, S2Setmap& pt2base, V2Imap& goodman) {
        char c;
        ss >> c;
        assert(c == '(');

        string sym = "";
        ss >> sym;
        unsigned int symI = sym2base[sym];
        //        printf("got symbol %s (%u)\n",sym.c_str(),symI);
        
        vector<unsigned int> kSyms;
        kSyms.push_back(symI);
        
        while(true) {
            c = ss.peek();
            if(c == ' ') { //it's a space
                ss.ignore(1); //ignore that space
            } else if(c == '(') { //nonterminal
                //get child node index
                unsigned int index = getRule(ss,pt2base,goodman);
                kSyms.push_back(index);                
            } else if (c == ')') {
                ss.ignore(1); //burn closing paren
                //      printf("Finished Rule with sym %s and %lu kids\n",sym.c_str(),kSyms.size()-1);
                unsigned int index = 0; 
                
                while(kSyms.size() > 3) { //try to add glue rule
                    //  printf("K = %lu\n",kSyms.size());
                    unsigned int r = kSyms.back();
                    kSyms.pop_back();
                    unsigned int l = kSyms.back();
                    kSyms.pop_back();

                    unsigned int glueI = nSym*2;
                    
                    vector<unsigned int> gluerule;
                    gluerule.push_back(glueI);//glue symbol
                    gluerule.push_back(l);
                    gluerule.push_back(r);

                    unsigned int glueindex = 0; 
                    V2Imap::iterator fter = goodman.find(gluerule);
                    if(fter == goodman.end()) { //new node
                        goodman[gluerule] = goodmanIndex;
                        baseSym.push_back(glueI);
                        glueindex = goodmanIndex;

                        canL.push_back(false);
                        canR.push_back(false);
                        
                        canL[l] = true;
                        canR[r] = true;

                        leftlook[l].push_back(make_pair(r,goodmanIndex));
                        
                        bmap[make_pair(l,r)].insert(goodmanIndex);
                        
                        goodmanIndex++;
                    } else { //seen it
                        glueindex = fter->second;
                    }
                    kSyms.push_back(glueindex);
                }

                V2Imap::iterator fter = goodman.find(kSyms);
                if(fter == goodman.end()) { //new node
                    goodman[kSyms] = goodmanIndex;
                    baseSym.push_back(symI);
                    index = goodmanIndex;

                    canL.push_back(false);
                    canR.push_back(false);
                    
                    goodmanIndex++;

                    if(kSyms.size() == 3) {
                        //add index -> l r
                        //    printf("BR : %u -> %u %u\n",index,kSyms[1],kSyms[2]);
                        canL[kSyms[1]] = true;
                        canR[kSyms[2]] = true;
                        leftlook[kSyms[1]].push_back(make_pair(kSyms[2],index));
                        bmap[make_pair(kSyms[1],kSyms[2])].insert(index);
                    } else { //one child
                        //add index -> k
                        umap[kSyms[1]].insert(index);
                        //printf("UR : %u -> %u\n",index,kSyms[1]);
                    }
                    
                } else { //seen it
                    index = fter->second;
                }
                                
                return index;
            } else { //terminal
                string term = "";
                while(ss.peek() != ')') {
                    term += ss.get();
                }
                //                printf("got terminal %s\n",term.c_str());
                ss.ignore(1); //burn closing paren
//.........这里部分代码省略.........
开发者ID:chonger,项目名称:BucketParser,代码行数:101,代码来源:BucketGrammar.hpp


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