blob: 29fe1c48bb6f654fc86fcd5b154d181a19151232 [file] [log] [blame]
Ratan Gupta309ac442016-12-13 20:40:06 +05301#pragma once
2#include <iostream>
3#include <fstream>
4#include <sstream>
5namespace slp
6{
7struct ConfigData
8{
9 std::string name;
10 std::string type;
11 std::string port;
12
13 friend std::istream& operator>>(std::istream& str, ConfigData& data)
14 {
15 std::string line;
16 constexpr auto DELIMITER = " ";
17 size_t delimtrPos = 0;
18 size_t delimtrPrevPos = 0;
19 std::array<std::string, 3>tokens;
20 std::getline(str, line);
21 size_t count = 0;
22
23 delimtrPos = line.find(DELIMITER, delimtrPrevPos);
24 while (delimtrPos != std::string::npos)
25 {
26 tokens[count] = line.substr(delimtrPrevPos, (delimtrPos - delimtrPrevPos));
27 delimtrPrevPos = delimtrPos + 1;
28
29 delimtrPos = line.find(DELIMITER, delimtrPrevPos);
30 if (delimtrPos == std::string::npos && delimtrPrevPos < line.length())
31 {
32 delimtrPos = line.length();
33 }
34
35 count++;
36 }
37
38 if (count > 2)
39 {
40 data.name = tokens[0];
41 data.type = tokens[1];
42 data.port = tokens[2];
43 }
44 else
45 {
46 str.setstate(std::ios::failbit);
47 }
48 return str;
49 }
50
51};
52}