diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-02-04 15:34:54 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-02-04 15:34:54 +0200 |
commit | d1b34452618d36eb486ff18b16f5d94acc6eeb07 (patch) | |
tree | 94bef542684ed235184f0694c7198b14bc5c652f | |
parent | 5ad4f467561511175c314018e0b3c6e30a3d145b (diff) |
Add support for multiple values in *-file options, add final newline
-rw-r--r-- | odb/generator.cxx | 29 | ||||
-rw-r--r-- | odb/options.cli | 26 |
2 files changed, 39 insertions, 16 deletions
diff --git a/odb/generator.cxx b/odb/generator.cxx index fcbc7ee..c255b02 100644 --- a/odb/generator.cxx +++ b/odb/generator.cxx @@ -91,7 +91,21 @@ namespace { ifstream ifs; open (ifs, file); - os << ifs.rdbuf (); + + // getline() will set the failbit if it failed to extract anything, + // not even the delimiter and eofbit if it reached eof before seeing + // the delimiter. + // + // We used to just do: + // + // os << ifs.rdbuf (); + // + // But that has some drawbacks: it won't end with a newline if the file + // doesn't end with one. There were also some issues with Windows newlines + // (we ended up doubling them). + // + for (string s; getline (ifs, s); ) + os << s << endl; } // Append prologue/interlude/epilogue. @@ -100,7 +114,7 @@ namespace append_logue (ostream& os, database db, database_map<vector<string> > const& text, - database_map<string> const& file, + database_map<vector<string> > const& file, char const* begin_comment, char const* end_comment) { @@ -110,10 +124,19 @@ namespace if (t || f) { os << begin_comment << endl; + if (t) append (os, text[db]); + if (f) - append (os, path (file[db])); + { + strings const& fs (file[db]); + + for (strings::const_iterator i (fs.begin ()); + i != fs.end (); ++i) + append (os, path (*i)); + } + os << end_comment << endl << endl; } diff --git a/odb/options.cli b/odb/options.cli index cf511d7..3dbb3f8 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -554,42 +554,42 @@ class options // Prologue files. // - database_map<std::string> --hxx-prologue-file + database_map<std::vector<std::string> > --hxx-prologue-file { "<file>", "Insert the content of <file> at the beginning of the generated C++ header file." }; - database_map<std::string> --ixx-prologue-file + database_map<std::vector<std::string> > --ixx-prologue-file { "<file>", "Insert the content of <file> at the beginning of the generated C++ inline file." }; - database_map<std::string> --cxx-prologue-file + database_map<std::vector<std::string> > --cxx-prologue-file { "<file>", "Insert the content of <file> at the beginning of the generated C++ source file." }; - database_map<std::string> --schema-prologue-file + database_map<std::vector<std::string> > --schema-prologue-file { "<file>", "Insert the content of <file> at the beginning of the generated schema C++ source file." }; - database_map<std::string> --sql-prologue-file + database_map<std::vector<std::string> > --sql-prologue-file { "<file>", "Insert the content of <file> at the beginning of the generated database schema file." }; - database_map<std::string> --migration-prologue-file + database_map<std::vector<std::string> > --migration-prologue-file { "<f>", "Insert the content of file <f> at the beginning of the generated database @@ -598,7 +598,7 @@ class options // Interlude files. // - database_map<std::string> --sql-interlude-file + database_map<std::vector<std::string> > --sql-interlude-file { "<file>", "Insert the content of <file> after all the \cb{DROP} and before any @@ -607,42 +607,42 @@ class options // Epilogue files. // - database_map<std::string> --hxx-epilogue-file + database_map<std::vector<std::string> > --hxx-epilogue-file { "<file>", "Insert the content of <file> at the end of the generated C++ header file." }; - database_map<std::string> --ixx-epilogue-file + database_map<std::vector<std::string> > --ixx-epilogue-file { "<file>", "Insert the content of <file> at the end of the generated C++ inline file." }; - database_map<std::string> --cxx-epilogue-file + database_map<std::vector<std::string> > --cxx-epilogue-file { "<file>", "Insert the content of <file> at the end of the generated C++ source file." }; - database_map<std::string> --schema-epilogue-file + database_map<std::vector<std::string> > --schema-epilogue-file { "<file>", "Insert the content of <file> at the end of the generated schema C++ source file." }; - database_map<std::string> --sql-epilogue-file + database_map<std::vector<std::string> > --sql-epilogue-file { "<file>", "Insert the content of <file> at the end of the generated database schema file." }; - database_map<std::string> --migration-epilogue-file + database_map<std::vector<std::string> > --migration-epilogue-file { "<f>", "Insert the content of file <f> at the end of the generated database |