真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

C++實(shí)現(xiàn)通用AST語法樹結(jié)構(gòu)-創(chuàng)新互聯(lián)

class ASTNode;
typedef std::mapPropertyContainer;
typedef std::vector ChildContainer;
class ASTNode: PropertyContainer, ChildContainer
{
public:
    ASTNode(){}
    ASTNode(std::initializer_listlist)
        : PropertyContainer (list)
    {

    }

    ChildContainer::reference operator[](size_t index) _GLIBCXX_NOEXCEPT
    {
        return std::vector::operator[](index);
    }

    ASTNode &operator<< (const ASTNode &node) _GLIBCXX_NOEXCEPT
    {
        push_back(node); return *this;
    }

    size_t size() const _GLIBCXX_NOEXCEPT
    {
        return std::vector::size();
    }

    templatevoid recursionChilds(Funct_ f) const _GLIBCXX_NOEXCEPT {
        foreachChilds([=](ChildContainer::const_reference ref) {
            ref.recursionChilds(f);
        });
    }

    templatevoid recursion(Funct_ f) const _GLIBCXX_NOEXCEPT {
        f(*this);
        recursionChilds(f);
    }

    templatevoid recursion(Funct_ f, int &level) const _GLIBCXX_NOEXCEPT {
        f(*this);
        level ++;
        foreachChilds([&](ChildContainer::const_reference ref) {
            ref.recursion(f, level);
        });
        level --;
    }

    templatevoid foreachChilds(Funct_ f) const _GLIBCXX_NOEXCEPT {
        std::for_each(ChildContainer::begin(), ChildContainer::end(), f);
    }

    templatevoid foreachPropertys(Funct_ f) const _GLIBCXX_NOEXCEPT {
        std::for_each(PropertyContainer::begin(), PropertyContainer::end(), f);
    }

    PropertyContainer::mapped_type &operator[](const std::string &key) _GLIBCXX_NOEXCEPT
    {
        return PropertyContainer::operator[](key);
    }

    std::vectorkeys() const _GLIBCXX_NOEXCEPT {
        std::vectorret;
        auto itera = PropertyContainer::begin();
        while (itera != PropertyContainer::end()) {
            ret.push_back(itera->first);
            itera ++;
        }
        return ret;
    }

    std::vectorvalues() const _GLIBCXX_NOEXCEPT {
        std::vectorret;
        auto itera = PropertyContainer::begin();
        while (itera != PropertyContainer::end()) {
            ret.push_back(itera->second);
            itera ++;
        }
        return ret;
    }

    size_t count() const _GLIBCXX_NOEXCEPT
    {
        return PropertyContainer::size();
    }

    void dump()
    {
        int level = 0;
        recursion([&](ChildContainer::const_reference ref){
            auto getHead = [=](int level) ->std::string {
                int c = 0; std::string ret;
                while (c< level) {
                    ret += " ";
                    c++;
                }
                return ret;
            };
            std::cout<< getHead(level);
            ref.foreachPropertys([&](PropertyContainer::const_reference ref)
            {
                std::cout<< ref.first<< ":"<< ref.second<< " ";
            });
            std::cout<< std::endl;
        }, level);
    }

    void dumpSave(const std::string &file)
    {
        std::ofstream ofstream;
        ofstream.open(file);

        int level = 0;
        recursion([&](ChildContainer::const_reference ref){
            auto getHead = [=](int level) ->std::string {
                int c = 0; std::string ret;
                while (c< level) {
                    ret += " ";
                    c++;
                }
                return ret;
            };
            ofstream<< getHead(level);
            ref.foreachPropertys([&](PropertyContainer::const_reference ref)
            {
                ofstream<< ref.first<< ":"<< ref.second<< " ";
            });
            ofstream<< std::endl;
        }, level);
    }

    void dumpLoad(const std::string &file)
    {

    }
};


ASTNode genRoot() {
    ASTNode root{{"name", "root"}};
    ASTNode one{{"name", "public"},{"start", "[0:0]"}};
    ASTNode two{{"name", "class"},{"start", "[0:7]"}};
    ASTNode three{{"name", "Hello"},{"start", "[0:13]"}};
    root<< one<< two<< three;
    root[0]<< one<< two<< three;
    root[0][0]<< one<< two<< three;
    root[0][0][0]<< one<< two<< three;
    root[1]<< one<< two<< three;
    root[2]<< one<< two<< three;
    return root;
}

int main(int argc, char *argv[])
{
    ASTNode root = genRoot();
    root.dump();
}

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

樅陽網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),樅陽網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為樅陽成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的樅陽做網(wǎng)站的公司定做!
標(biāo)題名稱:C++實(shí)現(xiàn)通用AST語法樹結(jié)構(gòu)-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://weahome.cn/article/dsedgd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部