1
0
Fork 0

[A] Added more c++ funcions

This commit is contained in:
seleznevae 2018-04-08 15:48:15 +03:00
parent 8bb0eaec66
commit 9838e6dc97
4 changed files with 75 additions and 23 deletions

View File

@ -4,18 +4,33 @@
int main()
{
fort::FTable table;
{
fort::FTable table;
// Fill table with data
table << fort::header
<< "Rank" << "Title" << "Year" << "Rating" << fort::endl
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endl
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endl
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endl
<< fort::separator
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endl
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endl
<< fort::endl;
std::cout << table.to_string() << std::endl;
}
// Fill table with data
table << fort::header
<< "Rank" << "Title" << "Year" << "Rating" << fort::endl
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endl
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endl
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endl
<< fort::separator
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endl
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endl;
std::cout << table.to_string();
{
fort::FTable table;
// Fill table with data
table << fort::header;
table.write_ln("Rank", "Title", "Year", "Rating");
table.write_ln("1", "The Shawshank Redemption", "1994", "9.5");
table.write_ln("2", "12 Angry Men", "1957", "8.8");
table.write_ln("3", "It's a Wonderful Life", "1946", "8.6");
table.write_ln("4", "2001: A Space Odyssey", "1968", "8.5");
table.write_ln("5", "Blade Runner", "1982", "8.1");
std::cout << table.to_string();
}
return 0;
}

View File

@ -107,6 +107,17 @@ SOFTWARE.
#endif
/*****************************************************************************
* RETURN CODES
* ***************************************************************************/
typedef int fort_status_t;
#define FT_SUCCESS 0
#define FT_MEMORY_ERROR -1
#define FT_ERROR -2
#define FT_EINVAL -3
#define IS_SUCCESS(arg) ((arg) >= 0)
#define IS_ERROR(arg) ((arg) < 0)
/*
* Wchar support

View File

@ -54,9 +54,11 @@ public:
template <typename T>
FTable &operator<<(const T &arg)
{
std::stringstream stream;
stream << arg;
ft_nwrite(table, 1, stream.str().c_str());
if (stream.tellp()) {
ft_nwrite(table, 1, stream.str().c_str());
stream = std::stringstream{};
}
return *this;
}
@ -71,10 +73,44 @@ public:
return *this;
}
bool write(const char *str)
{
return IS_SUCCESS(ft_write(table, str));
}
bool write_ln(const char *str)
{
return IS_SUCCESS(ft_write_ln(table, str));
}
bool write(const std::string &str)
{
return write(str.c_str());
}
bool write_ln(const std::string &str)
{
return write_ln(str.c_str());
}
template <typename T, typename ...Ts>
bool write(const T &arg, const Ts &...args)
{
return write(arg) && write(args...);
}
template <typename T, typename ...Ts>
bool write_ln(const T &arg, const Ts &...args)
{
if (sizeof...(args) == 0)
return write_ln(arg);
return write(arg) && write_ln(args...);
}
private:
FTABLE *table;
std::stringstream stream;
};
}

View File

@ -57,16 +57,6 @@ enum F_BOOL
#define SYS_LOG_ERROR(...)
/*****************************************************************************
* RETURN CODES
* ***************************************************************************/
typedef int fort_status_t;
#define FT_SUCCESS 0
#define FT_MEMORY_ERROR -1
#define FT_ERROR -2
#define FT_EINVAL -3
#define IS_SUCCESS(arg) ((arg) >= 0)
#define IS_ERROR(arg) ((arg) < 0)
/*****************************************************************************
* DEFAULT_SIZES