网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C++实现通用AST语法树结构-创新互联

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();
}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧

枞阳网站建设公司成都创新互联,枞阳网站设计制作,有大型网站制作公司丰富经验。已为枞阳成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的枞阳做网站的公司定做!
新闻名称:C++实现通用AST语法树结构-创新互联
标题URL:http://bjjierui.cn/article/dsedgd.html

其他资讯