File: numberlist.h

package info (click to toggle)
wsclean 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,968 kB
  • sloc: cpp: 85,742; python: 3,526; sh: 245; makefile: 21
file content (48 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef NUMBERLIST_H
#define NUMBERLIST_H

#include <cstdlib>
#include <string>

#include <aocommon/uvector.h>

namespace wsclean {

class NumberList {
 public:
  static aocommon::UVector<int> ParseIntList(const std::string& str) {
    aocommon::UVector<int> list;
    std::string temp = str;
    size_t pos = temp.find(",");
    while (pos != std::string::npos) {
      std::string idStr = temp.substr(0, pos);
      temp = temp.substr(pos + 1);
      int num = atoi(idStr.c_str());
      list.push_back(num);
      pos = temp.find(",");
    }
    int num = atoi(temp.c_str());
    list.push_back(num);
    return list;
  }

  static aocommon::UVector<double> ParseDoubleList(const std::string& str) {
    aocommon::UVector<double> list;
    std::string temp = str;
    size_t pos = temp.find(",");
    while (pos != std::string::npos) {
      std::string idStr = temp.substr(0, pos);
      temp = temp.substr(pos + 1);
      double num = atof(idStr.c_str());
      list.push_back(num);
      pos = temp.find(",");
    }
    double num = atof(temp.c_str());
    list.push_back(num);
    return list;
  }
};

}  // namespace wsclean

#endif