COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
stringlib.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
35 
38 #ifndef _STRINGLIB_H
39 #define _STRINGLIB_H 1
40 
41 #include "support/configCosmos.h"
42 #include "support/jsonobject.h"
43 
44 #include <errno.h>
45 #include <string>
46 #include <sstream>
47 
51 
52 vector < string > string_split(string in, string delimeters);
53 uint16_t string_parse(char *string, char *word[], uint16_t size);
54 int string_cmp(const char *wild, const char *string);
55 string to_hex_string(vector <uint8_t> buffer, bool ascii=false);
56 string to_string(char *value);
57 string to_hex(int64_t value, uint16_t digits=0, bool zerofill=false);
58 string to_signed(int64_t value, uint16_t digits=0, bool zerofill=false);
59 string to_unsigned(uint64_t value, uint16_t digits=0, bool zerofill=false);
60 string to_double(double value, uint16_t precision=0);
61 string to_mjd(double value);
62 string to_temperature(double value, char units='K', uint8_t precision=4);
63 string to_angle(double value, char units='R', uint8_t precision=4);
64 string to_bool(bool value);
65 string to_json(string key, string value);
66 string to_json(string key, double value);
67 string to_json(string key, int64_t value);
68 string to_json(string key, int32_t value);
69 string to_json(string key, int16_t value);
70 string to_json(string key, int8_t value);
71 string to_json(string key, uint64_t value);
72 string to_json(string key, uint32_t value);
73 string to_json(string key, uint16_t value);
74 string to_json(string key, uint8_t value);
75 string to_label(string label, string value);
76 string to_label(string label, double value, uint16_t precision=0, bool mjd=false);
77 string to_label(string label, int64_t value, uint16_t digits=0, bool hex=false);
78 string to_label(string label, int32_t value, uint16_t digits=0, bool hex=false);
79 string to_label(string label, int16_t value, uint16_t digits=0, bool hex=false);
80 string to_label(string label, int8_t value, uint16_t digits=0, bool hex=false);
81 string to_label(string label, uint64_t value, uint16_t digits=0, bool hex=false);
82 string to_label(string label, uint32_t value, uint16_t digits=0, bool hex=false);
83 string to_label(string label, uint16_t value, uint16_t digits=0, bool hex=false);
84 string to_label(string label, uint8_t value, uint16_t digits=0, bool hex=false);
85 string to_label(string label, bool value);
86 string clean_string(string value);
87 
88 // Class to parse a comma delimited string
89 class StringParser {
90 
91  vector<string> vect;
92 
93 public:
94  // the offset allows you to move the index by an offset value
95  // this can be useful if, for example, getFieldNumber(1) should logically be getFieldNumber(2)
96  // the offset then is 1
97  int offset;
98  StringParser(string str);
99  StringParser(string str, char delimiter);
100  string getFieldNumber(uint32_t index);
101  double getFieldNumberAsDouble(uint32_t index);
102  void splitString(string str, char delimiter);
104  int getFieldNumberAsInteger(uint32_t index);
105 };
106 
108 
109 #endif
double getFieldNumberAsDouble(uint32_t index)
Definition: stringlib.cpp:184
string to_temperature(double value, char units, uint8_t precision)
Definition: stringlib.cpp:300
void splitString(string str, char delimiter)
Definition: stringlib.cpp:150
string to_string(char *value)
Definition: stringlib.cpp:220
string to_unsigned(uint64_t value, uint16_t digits, bool zerofill)
Definition: stringlib.cpp:265
const string & str
Definition: json11.cpp:360
vector< string > vect
Definition: stringlib.h:91
string to_signed(int64_t value, uint16_t digits, bool zerofill)
Definition: stringlib.cpp:245
string to_hex_string(vector< uint8_t > buffer, bool ascii)
Definition: stringlib.cpp:204
size_t numberOfFields
Definition: stringlib.h:103
static char buffer[255]
Definition: propagator_simple.cpp:60
int getFieldNumberAsInteger(uint32_t index)
Definition: stringlib.cpp:202
Headers and definitions common to all COSMOS.
double mjd
Definition: udp_send.cpp:41
uint16_t string_parse(char *string, char *words[], uint16_t wmax)
Parse a string into words.
Definition: stringlib.cpp:78
delimiter
Definition: inputfile.py:6
Definition: stringlib.h:89
string getFieldNumber(uint32_t index)
Definition: stringlib.cpp:170
string to_bool(bool value)
Definition: stringlib.cpp:326
string clean_string(string value)
Definition: stringlib.cpp:432
string to_hex(int64_t value, uint16_t digits, bool zerofill)
Definition: stringlib.cpp:225
int offset
Definition: stringlib.h:97
StringParser(string str)
Definition: stringlib.cpp:143
int string_cmp(const char *wild, const char *string)
Definition: stringlib.cpp:110
string to_label(string label, double value, uint16_t precision, bool mjd)
Definition: stringlib.cpp:376
string to_json(string key, string value)
Definition: stringlib.cpp:334
string to_mjd(double value)
Definition: stringlib.cpp:298
string to_angle(double value, char units, uint8_t precision)
Definition: stringlib.cpp:313
string to_double(double value, uint16_t precision)
Definition: stringlib.cpp:285
vector< string > string_split(string in, string delimeters)
Parse a string.
Definition: stringlib.cpp:47