libwolfram20
WAQuery.h
Go to the documentation of this file.
1
10#ifndef WAQUERY_H
11#define WAQUERY_H
12
13#include <string>
14#include <set>
15#include <sstream>
16#include <vector>
17
21#define DEFAULT_TIMEOUT 5
22
26typedef struct {
27 float latitude;
28 float longitude;
29} Location;
30
36{
37public:
38 WAQuery();
39
40 std::string toString();
41
42 std::string getInput();
43 void setInput(std::string input);
44
45 void addFormat(std::string format);
46 void addFormat(const char *format);
47 void clearFormats();
48
49 void setTimeout(unsigned int value);
50
52
53 /*
54 * NOT REALESED
55 *
56 string getIP();
57 void setIP(string ip);
58
59 double* getLatLong();
60 void setLatLong(string latlong);
61 void setLatitude(double latitude);
62 void setLongitude(double longitude);
63
64 string getLocation();
65 void setLocation(string loc);
66
67 bool isMetric();
68 void setMetric(bool metric);
69
70 string getCurrency();
71 void setCurrency(string currency);
72
73 string getCountryCode();
74 void setCountryCode(string code);
75
76 bool isAllowTranslation();
77 void setAllowTranslation(bool allow);
78 */
79
81
82 void addPodTitle(std::string podtitle);
83 void clearPodTitles();
84
85 void addPodIndex(int podindex);
86 void clearPodIndexes();
87
88 void addPodScanner(std::string podscanner);
89 void clearPodScanners();
90
91 void addIncludePodID(std::string podid);
92 void clearIncludePodIDs();
93
94 void addExcludePodID(std::string podid);
95 void clearExcludePodIDs();
96
98
99 /*
100 * NOT REALESED
101 *
102 void addAssumption(string assumption);
103 void clearAssumptions();
104
105 //WAPodState[] getPodStates();
106 // This doesn't really work for <statelist>-type states. The query will work, but if you modify an existing
107 // query, you won't get the new state replacing the old state. Instead, you get chaining, so the old replacement happens
108 // followed by the new replacement. Probably still works, but it's inefficient. (I'm not sure if the order is guaranteed,
109 // so the old state might still be in effect.)
110 void addPodState(string podstate);
111 // This one is for <statelist> types, but not intended to be called by users, since they don't know what the id is.
112 void addPodState(string podstate, long id);
113 //void addPodState(WAPodState podstate);
114 void clearPodStates();
115
117
118 // Take values from an API-style URL.
119 //void fillFromURL(string url);
120 */
121
122private:
123 std::string _input;
124 unsigned int _timeout;
125 // TODO parsetimeout, formattimeout, podtimeout, totaltimeout
126
127 /*
128 * NOT REALESED
129 *
130 std::string ip; //!< Specifies a custom query location based on an IP address
131 std::string location; //!< Specifies a custom query location based on a string
132 // Objects, not double, so that they can have null == unassigned
133 Location _lat_long; //!< Specifies a custom query location based on a latitude/longitude pair
134
135 bool metric; //!< Lets you specify the preferred measurement system, either "metric" or "nonmetric" (US customary units)
136
137 // TODO img size attributes
138 */
139
144 std::vector<std::string> _formats;
145 std::vector<std::string> _podTitle;
146 std::vector<int> _podIndexes;
147 std::vector<std::string> _podScanners;
148 std::vector<std::string> _includePodIDs;
149 std::vector<std::string> _excludePodIDs;
150
151 static std::set<char> _special_char;
152
153 template <typename T> std::string VectorToStr(const char *prefix, bool individual, std::vector<T>& t);
154 template <typename T> std::string VectorToStr(std::string prefix, bool individual, std::vector<T>& t);
155
156 static std::string parseInput(std::string str);
157};
158
165template <class T>
166inline std::string to_string (const T& t) {
167 std::stringstream ss;
168 ss << t;
169 return ss.str();
170}
171
172#endif // WAQUERY_H
std::string to_string(const T &t)
Template for converting any data to string.
Definition: WAQuery.h:166
void addIncludePodID(std::string podid)
Adding a id config.
Definition: WAQuery.cpp:169
void addFormat(std::string format)
Adding a string format.
Definition: WAQuery.cpp:87
void addPodScanner(std::string podscanner)
Adding a string scanner.
Definition: WAQuery.cpp:153
std::string toString()
Returning a query param string.
Definition: WAQuery.cpp:26
std::string VectorToStr(const char *prefix, bool individual, std::vector< T > &t)
Concatenating a vector data to string.
Definition: WAQuery.cpp:204
void addPodTitle(std::string podtitle)
Adding a string title.
Definition: WAQuery.cpp:121
void clearPodIndexes()
Clear index config.
Definition: WAQuery.cpp:144
void addExcludePodID(std::string podid)
Removing an id config.
Definition: WAQuery.cpp:185
WAQuery()
Default constructor.
Definition: WAQuery.cpp:17
void clearFormats()
Clear format config.
Definition: WAQuery.cpp:103
void clearExcludePodIDs()
Clear excluded id config.
Definition: WAQuery.cpp:192
void setTimeout(unsigned int value)
Sets the timeout.
Definition: WAQuery.cpp:112
void clearPodScanners()
Clear scanner config.
Definition: WAQuery.cpp:160
void setInput(std::string input)
Set text for search.
Definition: WAQuery.cpp:78
std::string getInput()
Returning a search query text.
Definition: WAQuery.cpp:69
void addPodIndex(int podindex)
Adding a string index.
Definition: WAQuery.cpp:137
void clearPodTitles()
Clear title config.
Definition: WAQuery.cpp:128
void clearIncludePodIDs()
Clear included id config.
Definition: WAQuery.cpp:176
static std::string parseInput(std::string str)
Given an string it creates a copy but with % code More information here
Definition: WAQuery.cpp:48
API query petition manager.
Definition: WAQuery.h:36
unsigned int _timeout
The number of seconds to allow Wolfram|Alpha to compute results in the "scan" stage of processing (in...
Definition: WAQuery.h:124
std::vector< std::string > _includePodIDs
Specifies a pod ID to include in the result.
Definition: WAQuery.h:148
std::vector< std::string > _podTitle
Specifies a pod title to include in the result.
Definition: WAQuery.h:145
std::string _input
Text to search.
Definition: WAQuery.h:123
std::vector< std::string > _formats
The desired format for individual result pods It can be "image", "imagemap", "plaintext",...
Definition: WAQuery.h:144
static std::set< char > _special_char
Characters on https://es.wikipedia.org/wiki/C%C3%B3digo_porciento.
Definition: WAQuery.h:151
std::vector< std::string > _excludePodIDs
Specifies a pod ID to exclude from the result.
Definition: WAQuery.h:149
std::vector< std::string > _podScanners
Specifies that only pods produced by the given scanner should be returned.
Definition: WAQuery.h:147
std::vector< int > _podIndexes
Specifies the index(es) of the pod(s) to return.
Definition: WAQuery.h:146
Latitude/longitude.
Definition: WAQuery.h:26
float latitude
Latitude.
Definition: WAQuery.h:27
float longitude
Longitude.
Definition: WAQuery.h:28