8 #ifndef SIG_UTIL_LOAD_HPP
9 #define SIG_UTIL_LOAD_HPP
11 #include "../helper/helper_modules.hpp"
12 #include "../helper/maybe.hpp"
32 std::basic_ifstream<T>
54 std::basic_ifstream<IFS_CHAR>& ifs)
56 std::basic_string<IFS_CHAR> line;
60 while (ifs && std::getline(ifs, line)){
63 return static_cast<bool>(ifs);
83 class R =
typename impl::container_traits<C>::value_type
87 FilepassString
const& file_pass)
134 class ISTR = std::string,
135 class C = std::vector<ISTR>
137 auto load_line(FilepassString
const& file_pass) ->Maybe<C>
149 return tmp.empty() ?
Nothing(tmp) : Just<C>(std::move(tmp));
158 class ISTR = std::string,
160 class C = std::vector<R>
181 class R =
typename impl::container_traits<C>::value_type
185 std::basic_ifstream<IFS_CHAR>& ifs,
188 std::basic_string<IFS_CHAR> line;
192 while (ifs && std::getline(ifs, line)){
195 return static_cast<bool>(ifs);
228 class ISTR = std::string,
231 class R =
typename impl::container_traits<C>::value_type
235 FilepassString
const& file_pass,
291 class RT =
typename impl::container_traits<C>::value_type,
typename std::enable_if<!impl::container_traits<typename impl::container_traits<C>::value_type>::exist>::type*& =
enabler
295 FilepassString
const& file_pass,
296 std::string delimiter =
"\n")
298 auto read_str = load_line<std::string>(file_pass);
300 if (!
isJust(read_str))
return false;
302 if (delimiter ==
"\n"){
303 for (
auto const& line :
fromJust(read_str)){
349 class C = std::vector<R>,
typename std::enable_if<impl::container_traits<C>::exist && !impl::container_traits<typename impl::container_traits<C>::value_type>::exist>::type*& =
enabler
352 FilepassString
const& file_pass,
353 std::string delimiter =
"\n"
357 load_num(tmp, file_pass, delimiter);
358 return tmp.size() ? Just<C>(std::move(tmp)) :
Nothing(std::move(tmp));
394 class RC =
typename impl::container_traits<CC>::value_type,
395 class RT =
typename impl::container_traits<RC>::value_type
399 FilepassString
const& file_pass,
400 std::string delimiter)
402 auto read_str = load_line<std::string>(file_pass);
403 if (!
isJust(read_str))
return false;
405 for (
auto const& line :
fromJust(read_str)){
407 auto sp =
split(line, delimiter);
409 for (
auto const& v : sp){
447 class CC = std::vector<std::vector<R>>,
448 typename std::enable_if<impl::container_traits<typename impl::container_traits<CC>::value_type>::exist>::type*& =
enabler
451 FilepassString
const& file_pass,
452 std::string delimiter
457 return tmp.size() ? Just<CC>(std::move(tmp)) :
Nothing(std::move(tmp));
bool load_line(C &empty_dest, std::basic_ifstream< IFS_CHAR > &ifs)
ファイルから1行ずつ読み込む(ifstreamを指定)
auto split(S const &src, impl::string_t< S > const &delimiter) -> CSeq< TS >
文字列(src)をある文字列(delimiter)を目印に分割する
auto Nothing() -> typename impl::SameIf< T, void, typename boost::none_t, Maybe< T >>::type
値コンストラクタ
bool isJust(Maybe< T > const &m)
Justであるか調べる関数.Maybe a -> Bool.
typename std::conditional< std::is_same< T1, T2 >::value, TrueT, FalseT >::type type
bool load_num2d(CC &empty_dest, FilepassString const &file_pass, std::string delimiter)
2次元配列の数値(ex:行列)を読み込む
typename SameIf< T, std::string, std::ifstream, typename SameIf< T, std::wstring, std::wifstream, std::basic_ifstream< T > >::type >::type IfsSelector
T & fromJust(Maybe< T > &m)
Justから値を取り出す関数.Maybe a -> a.
#define SIG_FILE_LOCALE_INIT
typename StringId< typename remove_const_reference< typename std::decay< T >::type >::type >::type string_t
bool load_num(C &empty_dest, FilepassString const &file_pass, std::string delimiter="\n")
数値列を読み込む