Changeset 3902
- Timestamp:
- May 5, 2020, 4:17:54 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Makefile.am
r3901 r3902 49 49 test/bam_pair_iterator.test \ 50 50 test/bam_pair_iterator2.test \ 51 test/binary_read_write.test \ 51 52 test/chi2.test \ 52 53 test/cigar.test \ -
trunk/yat/random/random.cc
r3894 r3902 26 26 #include "yat/statistics/Histogram.h" 27 27 #include "yat/utility/Exception.h" 28 #include "yat/utility/utility.h" 28 29 29 30 #include <boost/smart_ptr.hpp> … … 126 127 unsigned long RNG::seed_from_devurandom(void) 127 128 { 128 unsigned char ulongsize=sizeof(unsigned long);129 boost::scoped_array<char> buffer(new char[ulongsize]);130 129 std::ifstream is("/dev/urandom", std::ios::binary); 131 is.read(buffer.get(),ulongsize); 130 unsigned long s=0; 131 utility::binary_read(is, s); 132 132 is.close(); 133 unsigned long s=0;134 memcpy(&s, buffer.get(), ulongsize);135 133 seed(s); 136 134 return s; -
trunk/yat/utility/Makefile.am
r3717 r3902 65 65 $(srcdir)/yat/utility/BasicVector.h \ 66 66 $(srcdir)/yat/utility/BasicQueue.h \ 67 $(srcdir)/yat/utility/BinaryIstreamIterator.h \ 68 $(srcdir)/yat/utility/BinaryOstreamIterator.h \ 67 69 $(srcdir)/yat/utility/BLAS_level1.h \ 68 70 $(srcdir)/yat/utility/BLAS_level2.h \ -
trunk/yat/utility/utility.h
r3855 r3902 50 50 #include <cmath> 51 51 #include <cstdlib> 52 #include <cstring> 52 53 #include <functional> 53 54 #include <limits> … … 77 78 */ 78 79 std::string basename(const std::string& fn); 80 81 /** 82 Read data from \a is into variable \a x. Data has typically been 83 written with binary_write(std::ostream& os, T). 84 85 \c T is expected to be a native numerical type. 86 87 \return \a is 88 89 \since New in yat 0.18 90 */ 91 template<typename T> 92 std::istream& binary_read(std::istream& is, T& x) 93 { 94 const unsigned char type_size=sizeof(T); 95 YAT_ASSERT(type_size <= 16); 96 char buffer[16]; 97 is.read(buffer, type_size); 98 memcpy(&x, buffer, type_size); 99 return is; 100 } 101 102 103 /** 104 Write value of \a x into ostream \a os in binary format. Since 105 the data is written in the native binary format, it may not be 106 portable between different architectures. 107 108 \c T is expected to be a native numerical type. 109 110 \see binary_read(std::istream&, T&) 111 112 \since New in yat 0.18 113 */ 114 template<typename T> 115 void binary_write(std::ostream& os, T x) 116 { 117 const unsigned char type_size=sizeof(T); 118 YAT_ASSERT(type_size <= 16); 119 char buffer[16]; 120 memcpy(buffer, &x, type_size); 121 os.write(buffer, type_size); 122 } 79 123 80 124 /**
Note: See TracChangeset
for help on using the changeset viewer.