Commit 73ce7370 authored by kraus's avatar kraus

adding file UUIDNameGenerator.h

parent 8255e6f5
......@@ -2,7 +2,9 @@
#include <string>
#include <sstream>
#include "boost/uuid/sha1.hpp"
#include "boost/uuid/uuid.hpp"
#include "boost/uuid/uuid_io.hpp"
#include "boost/uuid/name_generator.hpp"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
......@@ -20,7 +22,7 @@ public:
std::string hash_string = "";
foreach( std::string arg, arguments ) {
for (const std::string &arg: arguments ) {
hash_string += arg;
}
......@@ -29,28 +31,8 @@ public:
pidStr << world_pid;
hash_string += "_" + pidStr.str();
boost::uuids::detail::sha1 hash;
hash.process_bytes(hash_string.c_str(), hash_string.size());
unsigned int digest[5];
hash.get_digest(digest);
char hash_final[20];
for(int i=0; i < 5; i++) {
const char* tmp = reinterpret_cast<char*>(digest);
hash_final[i*4] = tmp[i*4+3];
hash_final[i*4 + 1] = tmp[i*4+2];
hash_final[i*4 + 2] = tmp[i*4+1];
hash_final[i*4 + 3] = tmp[i*4];
}
std::ostringstream hash_out;
hash_out << std::hex;
for(int i=0; i < 20; i++) {
hash_out << ((hash_final[i] & 0x000000F0) >> 4);
hash_out << (hash_final[i] & 0x0000000F);
}
return hash_out.str();
boost::uuids::name_generator_sha1 hash(boost::uuids::ns::dns());
return boost::uuids::to_string(hash(hash_string));
}
private:
......@@ -58,4 +40,4 @@ private:
UUIDNameGenerator() {}
~UUIDNameGenerator() {}
};
};
\ No newline at end of file
......@@ -7,7 +7,7 @@
NSGA2
Implements data exchange trough files.
file: nsga2_io.c
author: Marco Laumanns, laumanns@tik.ee.ethz.ch
......@@ -33,25 +33,25 @@ int read_pop(char *filename, pop *pp, int size, int dim)
char tag[4];
FILE *fp;
int result;
assert(dim >= 0);
assert(pp != NULL);
fp = fopen(filename, "r");
assert(fp != NULL);
fscanf(fp, "%d", &entries);
result = fscanf(fp, "%d", &entries);
if (entries == 0) /* file has not been written yet */
{
return (1); /* signalling that reading failed */
}
assert(entries == size * (dim + 1));
for (j = 0; j < size; j++)
{
/* reading index of individual */
result = fscanf(fp, "%d", &(pp->ind_array[j]->index));
for (i = 0; i < dim; i++)
{
/* reading objective values of ind */
......@@ -64,9 +64,9 @@ int read_pop(char *filename, pop *pp, int size, int dim)
}
}
}
/* after all data elements: "END" expected */
fscanf(fp, "%s", tag);
result = fscanf(fp, "%s", tag);
if (strcmp(tag, "END") != 0)
{
fclose(fp);
......@@ -75,13 +75,13 @@ int read_pop(char *filename, pop *pp, int size, int dim)
else /* "END" ok */
{
fclose(fp);
/* delete file content if reading successful */
fp = fopen(filename, "w");
assert(fp != NULL);
fprintf(fp, "0");
fclose(fp);
return (0); /* signalling that reading was successful */
}
}
......@@ -95,17 +95,17 @@ void write_pop(char* filename, pop* pp, int size)
FILE *fp;
assert(0 <= size <= pp->size);
fp = fopen(filename, "w");
assert(fp != NULL);
fprintf(fp, "%d\n", size); /* number of elements */
for (i = 0; i < size; i++)
{
fprintf(fp, "%d\n", pp->ind_array[i]->index);
}
fprintf(fp, "END");
fclose(fp);
}
......@@ -115,16 +115,18 @@ void write_pop(char* filename, pop* pp, int size)
int check_file(char* filename)
{
int control_element = 1;
FILE *fp;
fp = fopen(filename, "r");
assert(fp != NULL);
fscanf(fp, "%d", &control_element);
if (fscanf(fp, "%d", &control_element) != 1) {
fprintf(stderr, "Couldn't read file '%s'.", filename);
}
fclose(fp);
if(0 == control_element)
return (0); /* file is ready for writing */
else
return (1); /* file is not ready for writing */
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment