summaryrefslogtreecommitdiff
path: root/trunk/glagen/dll/classes/Data_string.hh
diff options
context:
space:
mode:
authorhugues <hugues@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c>2005-02-10 23:10:51 +0000
committerhugues <hugues@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c>2005-02-10 23:10:51 +0000
commitc50bc6329ff6e336de47efa7b2275c77e85a75a1 (patch)
treeeca3a8af85bcf95047caa027aa01d9cfc47a0cff /trunk/glagen/dll/classes/Data_string.hh
parent42d83a68fc1cd45019ddbebee041962d2a1783b9 (diff)
Initial revision
git-svn-id: file:///usr/local/opt/svn/repos/glagen@3 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c
Diffstat (limited to 'trunk/glagen/dll/classes/Data_string.hh')
-rw-r--r--trunk/glagen/dll/classes/Data_string.hh62
1 files changed, 62 insertions, 0 deletions
diff --git a/trunk/glagen/dll/classes/Data_string.hh b/trunk/glagen/dll/classes/Data_string.hh
new file mode 100644
index 0000000..a5f9131
--- /dev/null
+++ b/trunk/glagen/dll/classes/Data_string.hh
@@ -0,0 +1,62 @@
+#ifndef DATA_STRING_HH_
+# define DATA_STRING_HH_
+
+#include <iostream>
+#include <string>
+#include <unistd.h> // Pour write/read
+
+#include <errno.h>
+
+using namespace std;
+
+class Data_string
+{
+public:
+ Data_string() : _str("") {};
+ Data_string(const string& str) : _str(str) {};
+
+ void write_data(const int& fd) const
+ {
+
+ std::cout << "Donnees envoyes" << std::endl << _str << std::endl;
+ unsigned int size = _str.size();
+ write(fd, &size, sizeof(unsigned int));
+ for (unsigned int i = 0; i < size; ++i)
+ {
+ char car = _str[i];
+ write(fd, &car, sizeof(char));
+ }
+ }
+
+ void read_data(const int& fd)
+ {
+ unsigned int size = 0;
+ do
+ {
+ errno = 0;
+ read(fd, &size, sizeof(size));
+ }
+ while (errno == 4);
+
+ _str = "";
+ for (unsigned int i = 0; i < size; ++i)
+ {
+ char car;
+ do
+ {
+ errno = 0;
+ read(fd, &car, sizeof(char));
+ }
+ while (errno == 4);
+ _str += car;
+ }
+
+ std::cout << "Reception message sur le file descriptor :" << fd
+ << std::endl << _str << std::endl;
+ }
+
+private:
+ string _str;
+};
+
+#endif // DATA_STRING