33 #ifndef _FINRESDYN_SAVECOVER_H_ 34 #define _FINRESDYN_SAVECOVER_H_ 51 inline void byte2hex (std::ostream &out,
unsigned int byte)
53 const char symbols [16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
54 '7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
55 out << symbols [(byte >> 4) & 0x0F] << symbols [byte & 0x0F];
61 inline void double2hex (std::ostream &out,
const double &x)
65 const unsigned char *numBytes =
66 reinterpret_cast<const unsigned char *
> (&number);
72 if (*reinterpret_cast<const char *> (&testByte) == 1)
74 for (
int i =
sizeof (
double) - 1; i >= 0; -- i)
81 for (
unsigned int i = 0; i <
sizeof (double); ++ i)
98 std::ofstream f (filename);
100 throw "Cannot create a file to save the cover to.";
103 int dim = cover. dim ();
106 double *leftBounds =
new double [dim];
107 double *rightBounds =
new double [dim];
108 for (
int n = 0; n < cover. size (); ++ n)
111 cover.
get (n, leftBounds, rightBounds);
114 for (
int i = 0; i < dim; ++ i)
116 f << (i ?
") x (" :
"(") << leftBounds [i] <<
117 "," << rightBounds [i];
122 for (
int i = 0; i < dim; ++ i)
124 f << (i ?
") x (" :
"(");
131 delete [] rightBounds;
132 delete [] leftBounds;
138 template <
class UnknownCover>
139 inline void saveCover (
const UnknownCover &cover,
const char *filename)
141 throw "Trying to save a cover of unsupported type to a file.";
146 #endif // _FINRESDYN_SAVECOVER_H_ Various output streams for the program.
void double2hex(std::ostream &out, const double &x)
Writes a double precision floating-point number in the hexadecimal way as bytes.
A cover of a subset in R^n consisting of open boxes.
void byte2hex(std::ostream &out, unsigned int byte)
Writes a given unsigned byte in the hexadecimal way.
void saveCover(const tCoverBoxes< double > &cover, const char *filename)
Saves the given cover to a text file.