Skip to content

Commit

Permalink
fix an issue for conda-build
Browse files Browse the repository at this point in the history
  • Loading branch information
milkschen committed Mar 10, 2022
1 parent 38fd43b commit 6c962c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/leviosam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ int main(int argc, char** argv) {
std::cerr << "[E::main] Option `-f` must be set when `-x` is not empty\n";
exit(1);
} else {
std::string yaml = Yaml::file_get_contents<std::string>(args.realign_yaml);
const char *fc = args.realign_yaml.c_str();
std::string yaml = Yaml::file_get_contents<std::string>(fc);
ryml::Tree realign_tree = ryml::parse_in_arena(ryml::to_csubstr(yaml));
args.aln_opts.deserialize_realn(realign_tree);
args.aln_opts.print_parameters();
Expand Down
37 changes: 2 additions & 35 deletions src/yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,6 @@

namespace Yaml {

template<class CharContainer> CharContainer file_get_contents(const char *filename);
template<class CharContainer> size_t file_get_contents(const char *filename, CharContainer *v);

// helper functions for sample_parse_file()

C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4996) // fopen: this function or variable may be unsafe
/** load a file from disk and return a newly created CharContainer */
template<class CharContainer>
size_t file_get_contents(const std::string& filename, CharContainer *v)
{
::FILE *fp = ::fopen(filename.data(), "rb");
C4_CHECK_MSG(fp != nullptr, "[E::yaml::file_get_contents] Could not open file %s", filename);
::fseek(fp, 0, SEEK_END);
long sz = ::ftell(fp);
v->resize(static_cast<typename CharContainer::size_type>(sz));
if(sz)
{
::rewind(fp);
size_t ret = ::fread(&(*v)[0], 1, v->size(), fp);
C4_CHECK(ret == (size_t)sz);
}
::fclose(fp);
return v->size();
}

/** load a file from disk into an existing CharContainer */
template<class CharContainer>
CharContainer file_get_contents(const std::string& filename)
{
CharContainer cc;
file_get_contents(filename, &cc);
return cc;
}

std::string read_yaml_raw(std::ifstream &f) {
return std::string(
(std::istreambuf_iterator<char>(f)),
Expand All @@ -53,7 +19,8 @@ std::string read_yaml_raw(const std::string& fn) {
}

ryml::Tree parse_yaml(const std::string& filename) {
std::string contents = file_get_contents<std::string>(filename);
const char *c = filename.c_str();
std::string contents = file_get_contents<std::string>(c);
ryml::Tree tree = ryml::parse_in_arena(ryml::to_csubstr(contents));
return tree;
}
Expand Down
38 changes: 36 additions & 2 deletions src/yaml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,47 @@

namespace Yaml {

template<class CharContainer> CharContainer file_get_contents(const char *filename);
template<class CharContainer> size_t file_get_contents(const char *filename, CharContainer *v);

template<class CharContainer>
CharContainer file_get_contents(const char* filename);

// helper functions for sample_parse_file()

// C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4996) // fopen: this function or variable may be unsafe
/** load a file from disk and return a newly created CharContainer */
template<class CharContainer>
size_t file_get_contents(const char* filename, CharContainer *v)
{
::FILE *fp = ::fopen(filename, "rb");
C4_CHECK_MSG(fp != nullptr, "[E::yaml::file_get_contents] Could not open file %s", filename);
::fseek(fp, 0, SEEK_END);
long sz = ::ftell(fp);
v->resize(static_cast<typename CharContainer::size_type>(sz));
if(sz)
{
::rewind(fp);
size_t ret = ::fread(&(*v)[0], 1, v->size(), fp);
C4_CHECK(ret == (size_t)sz);
}
::fclose(fp);
return v->size();
}

/** load a file from disk into an existing CharContainer */
template<class CharContainer>
CharContainer file_get_contents(const std::string& filename);
CharContainer file_get_contents(const char* filename)
{
CharContainer cc;
file_get_contents(filename, &cc);
return cc;
}

// std::string read_yaml_raw(std::ifstream& f);
std::string read_yaml_raw(std::ifstream &f);
// std::string read_yaml_raw(const std::string& fn);
ryml::Tree parse_yaml(const std::string& filename);
ryml::Tree parse_yaml(const char* filename);

};

Expand Down

0 comments on commit 6c962c6

Please sign in to comment.