hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCEFileStream.cpp
Go to the documentation of this file.
1 #include <Poco/Path.h>
2 #include <sstream>
3 #include <ctype.h>
4 
5 #include "DRCEMessageConst.hpp"
6 #include "DRCEFileStream.hpp"
7 
8 namespace HCE
9 {
10 namespace drce
11 {
12 //-----------------------------------------------------------------------------
14 : fs()
15 {
16 }
17 //-----------------------------------------------------------------------------
18 FileStream::FileStream(const std::string& fileName, OpenMode openMode)
19 : fs(fileName.c_str(), openMode)
20 {
21 }
22 //-----------------------------------------------------------------------------
24 {
25  close();
26 }
27 //-----------------------------------------------------------------------------
28 bool FileStream::isOpen(void) const
29 {
30  return fs.is_open();
31 }
32 //-----------------------------------------------------------------------------
33 void FileStream::open(const std::string& fileName, OpenMode openMode)
34 {
35  fs.open(fileName.c_str(), openMode);
36 }
37 //-----------------------------------------------------------------------------
39 {
40  if (fs.is_open())
41  fs.close();
42 }
43 //-----------------------------------------------------------------------------
45 {
46  fs << data;
47  fs.flush();
48  return *this;
49 }
50 //-----------------------------------------------------------------------------
52 {
53  fs.seekg(0, std::ios::end);
54  data.resize(fs.tellg());
55  fs.seekg(0, std::ios::beg);
56  fs.read(const_cast<char*>(data.c_str()), data.size());
57  return *this;
58 }
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 std::string FileStream::getDataFileName(const std::string& dir, unsigned int taskId)
62 {
63  std::ostringstream ostr;
64  ostr << dir << "/" << taskId << "." << drce_const::dataFileExt;
65  return ostr.str();
66 }
67 //-----------------------------------------------------------------------------
68 std::string FileStream::getStatusFileName(const std::string& dir, unsigned int taskId)
69 {
70  std::ostringstream ostr;
71  ostr << dir << "/" << taskId;
72  return ostr.str();
73 }
74 //-----------------------------------------------------------------------------
75 std::string FileStream::getRequestFileName(const std::string& dir, unsigned int taskId)
76 {
77  std::ostringstream ostr;
78  ostr << dir << "/" << taskId << "." << drce_const::requestFileExt;
79  return ostr.str();
80 }
81 //-----------------------------------------------------------------------------
82 std::string FileStream::getDumpFileName(const std::string& dir, const std::string& nodeName)
83 {
84  return dir+"/"+nodeName+"_"+drce_const::dumpFileName;
85 }
86 //-----------------------------------------------------------------------------
87 bool FileStream::isStatusFileName(const std::string& fileName)
88 {
89  Poco::Path path(fileName);
90  char* str = const_cast<char*>(path.getFileName().c_str());
91  int symbols = 0;
92  int digits = 0;
93  while(*str != 0)
94  {
95  ++symbols;
96  if(isdigit(*str++))
97  ++digits;
98  }
99  return (symbols==digits);
100 }
101 //-----------------------------------------------------------------------------
102 } // end namespace drce
103 } // end namespace HCE