Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bin_manip.h"
- write_le_int32::write_le_int32(const int32_t& n) : _n(n){}
- std::basic_ostream<char> & operator<<(std::basic_ostream<char> & ofs, const write_le_int32 & wlei32) {
- return wlei32(ofs);
- }
- std::basic_ostream<char> & write_le_int32::operator()(std::basic_ostream<char> & ofs) const {
- ofs.write((char*) & _n, sizeof(_n));
- return ofs;
- }
- read_le_int32::read_le_int32(std::int32_t & n) : _n(n) {}
- std::basic_istream<char> & operator>>(std::basic_istream<char> & ifs, const read_le_int32 rlei32) {
- return rlei32(ifs);
- }
- std::basic_istream<char> & read_le_int32::operator()(std::basic_istream<char> & ifs) const {
- ifs.read((char*) & _n, sizeof(_n));
- return ifs;
- }
- read_bool::read_bool(bool & b) : _b(b) {}
- std::basic_istream<char> & operator>>(std::basic_istream<char> & ifs, const read_bool & rb) {
- return rb(ifs);
- }
- std::basic_istream<char> & read_bool::operator()(std::basic_istream<char> & ifs) const {
- ifs.read((char*) & _b, sizeof(_b));
- return ifs;
- }
- write_bool::write_bool(const bool & b) : _b(b) {}
- std::basic_ostream<char>& operator<<(std::basic_ostream<char> & ofs, const write_bool & wb) {
- return wb(ofs);
- }
- std::basic_ostream<char> & write_bool::operator()(std::basic_ostream<char> & ofs) const {
- ofs.write((char*) & _b, sizeof(_b));
- return ofs;
- }
- write_c_str::write_c_str(char * const str) : _str(str) {}
- std::basic_ostream<char>& operator<<(std::basic_ostream<char> & ofs, const write_c_str & wstr) {
- return wstr(ofs);
- }
- std::basic_ostream<char> & write_c_str::operator()(std::basic_ostream<char> & ofs) const {
- int32_t index = 0;
- while (_str[index] != '\0') {
- ofs.write((char*) & _str[index], sizeof(char));
- index++;
- }
- ofs.write((char*) & _str[index], sizeof(char));
- return ofs;
- }
- read_c_str::read_c_str(char * str, size_t size) : _str(str), _size(size) {}
- std::basic_istream<char>& operator>>(std::basic_istream<char> & ifs, const read_c_str & rs) {
- return rs(ifs);
- }
- std::basic_istream<char> & read_c_str::operator()(std::basic_istream<char> & ifs) const {
- size_t index = 0;
- char last_char = 'a';
- while (index < _size && last_char != '\0') {
- ifs.read((char*) & last_char, sizeof(char));
- _str[index++] = last_char;
- }
- if (index == _size && _str[index] != '\0') {
- ifs.setstate(std::ios::failbit);
- }
- return ifs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement