csv_name.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup diskio
  16. //! @{
  17. namespace csv_opts
  18. {
  19. typedef unsigned int flag_type;
  20. struct opts
  21. {
  22. const flag_type flags;
  23. inline explicit opts(const flag_type in_flags);
  24. inline const opts operator+(const opts& rhs) const;
  25. };
  26. inline
  27. opts::opts(const flag_type in_flags)
  28. : flags(in_flags)
  29. {}
  30. inline
  31. const opts
  32. opts::operator+(const opts& rhs) const
  33. {
  34. const opts result( flags | rhs.flags );
  35. return result;
  36. }
  37. // The values below (eg. 1u << 0) are for internal Armadillo use only.
  38. // The values can change without notice.
  39. static const flag_type flag_none = flag_type(0 );
  40. static const flag_type flag_trans = flag_type(1u << 0);
  41. static const flag_type flag_no_header = flag_type(1u << 1);
  42. static const flag_type flag_with_header = flag_type(1u << 2);
  43. struct opts_none : public opts { inline opts_none() : opts(flag_none ) {} };
  44. struct opts_trans : public opts { inline opts_trans() : opts(flag_trans ) {} };
  45. struct opts_no_header : public opts { inline opts_no_header() : opts(flag_no_header ) {} };
  46. struct opts_with_header : public opts { inline opts_with_header() : opts(flag_with_header) {} };
  47. static const opts_none none;
  48. static const opts_trans trans;
  49. static const opts_no_header no_header;
  50. static const opts_with_header with_header;
  51. }
  52. struct csv_name
  53. {
  54. typedef field<std::string> header_type;
  55. const std::string filename;
  56. const csv_opts::opts opts;
  57. header_type header_junk;
  58. const header_type& header_ro;
  59. header_type& header_rw;
  60. inline
  61. csv_name(const std::string& in_filename, const csv_opts::opts& in_opts = csv_opts::no_header)
  62. : filename (in_filename)
  63. , opts (in_opts )
  64. , header_ro(header_junk)
  65. , header_rw(header_junk)
  66. {}
  67. inline
  68. csv_name(const std::string& in_filename, field<std::string>& in_header)
  69. : filename (in_filename )
  70. , opts (csv_opts::with_header)
  71. , header_ro(in_header )
  72. , header_rw(in_header )
  73. {}
  74. inline
  75. csv_name(const std::string& in_filename, const field<std::string>& in_header)
  76. : filename (in_filename )
  77. , opts (csv_opts::with_header)
  78. , header_ro(in_header )
  79. , header_rw(header_junk )
  80. {}
  81. inline
  82. csv_name(const std::string& in_filename, field<std::string>& in_header, const csv_opts::opts& in_opts)
  83. : filename (in_filename )
  84. , opts (csv_opts::with_header + in_opts)
  85. , header_ro(in_header )
  86. , header_rw(in_header )
  87. {}
  88. inline
  89. csv_name(const std::string& in_filename, const field<std::string>& in_header, const csv_opts::opts& in_opts)
  90. : filename (in_filename )
  91. , opts (csv_opts::with_header + in_opts)
  92. , header_ro(in_header )
  93. , header_rw(header_junk )
  94. {}
  95. };
  96. //! @}