github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/common/ir_conf_reader.h (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  #pragma once
    21  #include "common/common.h"
    22  #include "common/ir_ref.h"
    23  #include "common/version.h"
    24  
    25  namespace boost{
    26  namespace property_tree{
    27    template <typename T1, typename T2, typename Compare > class basic_ptree;
    28    typedef basic_ptree<std::string, std::string, std::less<std::string> > ptree;
    29  }}
    30  
    31  namespace neb {
    32  
    33  struct json_general_failure : public std::exception {
    34    inline json_general_failure(const std::string &msg) : m_msg(msg) {}
    35    inline const char *what() const throw() { return m_msg.c_str(); }
    36  protected:
    37    std::string m_msg;
    38  };
    39  
    40  class ir_conf_reader {
    41  public:
    42    ir_conf_reader(const std::string &conf_fp);
    43    ~ir_conf_reader();
    44    ir_conf_reader(const ir_conf_reader &icr) = delete;
    45    ir_conf_reader &operator=(const ir_conf_reader &icr) = delete;
    46  
    47    inline const ir_ref &self_ref() const { return m_self_ref; }
    48    inline const std::vector<ir_ref> depends() const { return m_depends; }
    49    inline block_height_t available_height() const { return m_available_height; }
    50    inline const std::vector<std::string> cpp_files() const { return m_cpp_files; }
    51    inline const std::vector<std::string> include_header_files() const { return m_include_header_files; }
    52    inline const std::vector<std::string> link_files() const { return m_link_files; }
    53    inline const std::vector<std::string> link_path() const { return m_link_path; }
    54    inline const std::vector<std::string> flags() const { return m_flags; }
    55  
    56  protected:
    57    ir_ref m_self_ref;
    58    std::vector<ir_ref> m_depends;
    59    block_height_t m_available_height;
    60    std::vector<std::string> m_cpp_files;
    61    std::vector<std::string> m_include_header_files;
    62    std::vector<std::string> m_link_files;
    63    std::vector<std::string> m_link_path;
    64    std::vector<std::string> m_flags;
    65  
    66  private:
    67    void set_ir_ref_by_ptree(ir_ref &ir, const boost::property_tree::ptree &ptree);
    68    void read_json_file(const std::string &conf_fp, boost::property_tree::ptree &json_root);
    69    void get_ir_fp(const boost::property_tree::ptree &json_root);
    70    void get_self_ref(const boost::property_tree::ptree &json_root);
    71    void get_depends(const boost::property_tree::ptree &json_root);
    72    void get_available_height(const boost::property_tree::ptree &json_root);
    73    void get_clang_arguments(const boost::property_tree::ptree &json_root,
    74                                             const std::string &key,
    75                                             std::vector<std::string> &container);
    76  
    77  };
    78  } // namespace neb