Instrument Neutral Distributed Interface INDI  2.0.2
fitskeyword.cpp
Go to the documentation of this file.
1 
20 #include "fitskeyword.h"
21 #include <cmath>
22 #include <sstream>
23 
24 namespace INDI
25 {
26 
28  val_int64(0),
29  m_type(VOID)
30 {
31 }
32 
33 FITSRecord::FITSRecord(const char *key, const char *value, const char *comment) :
34  m_key(key),
35  m_type(STRING)
36 {
37  if (value)
38  val_str = std::string(value);
39 
40  if(comment)
41  m_comment = std::string(comment);
42 }
43 
44 FITSRecord::FITSRecord(const char *key, int64_t value, const char *comment) :
45  val_int64(value),
46  val_str(std::to_string(value)),
47  m_key(key),
48  m_type(LONGLONG)
49 {
50  if(comment)
51  m_comment = std::string(comment);
52 }
53 
54 /*FITSRecord::FITSRecord(const char *key, uint64_t value, const char *comment) :
55  val_uint64(value),
56  val_str(std::to_string(value)),
57  m_key(key),
58  m_type(ULONGLONG)
59 {
60  if(comment)
61  m_comment = std::string(comment);
62 }*/
63 
64 FITSRecord::FITSRecord(const char *key, double value, int decimal, const char *comment) :
65  val_double(value),
66  m_key(key),
67  m_type(DOUBLE),
68  m_decimal(decimal)
69 {
70  std::stringstream ss;
71  ss.precision(decimal);
72  ss << value;
73  val_str = ss.str();
74 
75  if(comment)
76  m_comment = std::string(comment);
77 }
78 
79 FITSRecord::FITSRecord(const char *comment) :
80  m_key("COMMENT"),
81  m_type(COMMENT)
82 {
83  if(comment)
84  m_comment = std::string(comment);
85 }
86 
88 {
89  return m_type;
90 }
91 
92 const std::string &FITSRecord::key() const
93 {
94  return m_key;
95 }
96 
97 const std::string &FITSRecord::valueString() const
98 {
99  return val_str;
100 }
101 
102 int64_t FITSRecord::valueInt() const
103 {
104  if (m_type == LONGLONG)
105  return val_int64;
106  else
107  return 0;
108 }
109 
110 /*uint64_t FITSRecord::valueUInt() const
111 {
112  if (m_type == ULONGLONG)
113  return val_uint64;
114  else
115  return 0;
116 }*/
117 
119 {
120  if (m_type == DOUBLE)
121  return val_double;
122  else
123  return NAN;
124 }
125 
126 const std::string &FITSRecord::comment() const
127 {
128  return m_comment;
129 }
130 
132 {
133  return m_decimal;
134 }
135 
136 }
137 
138 
int decimal() const
const std::string & key() const
Definition: fitskeyword.cpp:92
double valueDouble() const
int64_t val_int64
Definition: fitskeyword.h:58
const std::string & valueString() const
Definition: fitskeyword.cpp:97
int64_t valueInt() const
Type type() const
Definition: fitskeyword.cpp:87
const std::string & comment() const
Namespace to encapsulate INDI client, drivers, and mediator classes.
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.h:23613
Definition: json.h:4973