9 |
|
#include "InputType.hpp" |
10 |
|
|
11 |
|
#ifdef _WIN32 |
12 |
< |
#pragma warning(disable:4267) |
12 |
> |
#pragma warning(disable:4267 4288) |
13 |
|
#endif |
14 |
|
|
15 |
|
#include <menes-app/simple.hpp> |
17 |
|
#include <menes-xml/nodeset.hpp> |
18 |
|
#include <menes-xml/parse.hpp> |
19 |
|
|
20 |
+ |
struct Environment |
21 |
+ |
{ |
22 |
+ |
ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } } |
23 |
+ |
} env; |
24 |
+ |
|
25 |
+ |
struct Item |
26 |
+ |
{ |
27 |
+ |
DataType type; |
28 |
+ |
ext::String data; |
29 |
+ |
InputType input; |
30 |
+ |
Item(const DataType& type, const ext::String& data, const InputType& input_) : type(type), data(data), input(input_) {} |
31 |
+ |
}; |
32 |
+ |
|
33 |
|
int Main(const app::Options& options) |
34 |
|
{ |
35 |
|
Represent represent; |
62 |
|
api::Cout << after << ios::Flush; |
63 |
|
} |
64 |
|
|
52 |
– |
struct Represent::Item |
53 |
– |
{ |
54 |
– |
DataType type; |
55 |
– |
ext::String data; |
56 |
– |
InputType input; |
57 |
– |
Item(const DataType& type, const ext::String& data, const InputType& input) : type(type), data(data), input(input) {} |
58 |
– |
}; |
59 |
– |
|
65 |
|
void Represent::parse() |
66 |
|
{ |
67 |
|
ext::String query(env.get("QUERY_STRING")); |
317 |
|
template <typename Type> |
318 |
|
Type Represent::input(const Item& item) |
319 |
|
{ |
320 |
< |
// XXX: implement |
316 |
< |
|
317 |
< |
return lexical_cast<Type>(item.data); |
318 |
< |
} |
319 |
< |
|
320 |
< |
template <> |
321 |
< |
bool Represent::input(const Item& item) |
322 |
< |
{ |
323 |
< |
// XXX: implement |
320 |
> |
bool signed_(etl::Limits<Type>::IsSigned); |
321 |
|
|
322 |
< |
try { return lexical_cast<bool>(item.data); } catch (ext::Exception) { return false; } |
322 |
> |
switch (item.input) |
323 |
> |
{ |
324 |
> |
default: |
325 |
> |
try { return lexical_cast<Type>(item.data); } catch (ext::Exception) { return 0; } |
326 |
> |
case InputType::INPUT_Binary: |
327 |
> |
return Binary(item.data, signed_).convert<Type>(signed_); |
328 |
> |
case InputType::INPUT_Hexadecimal: |
329 |
> |
return Hexadecimal(item.data, signed_).convert<Type>(signed_); |
330 |
> |
} |
331 |
|
} |
332 |
|
|
333 |
|
template <> |
334 |
|
char Represent::input(const Item& item) |
335 |
|
{ |
336 |
< |
// XXX: implement |
337 |
< |
|
338 |
< |
return item.data.First(); |
336 |
> |
switch (item.input) |
337 |
> |
{ |
338 |
> |
default: |
339 |
> |
return item.data.First(); |
340 |
> |
case InputType::INPUT_Binary: |
341 |
> |
return Binary(item.data, false).convert<char>(false); |
342 |
> |
case InputType::INPUT_Hexadecimal: |
343 |
> |
return Hexadecimal(item.data, false).convert<char>(false); |
344 |
> |
} |
345 |
|
} |
346 |
|
|
347 |
< |
// XXX: constructing a string from Binary or Hexadecimal seems to dangerous |
347 |
> |
// XXX: constructing a string from Binary or Hexadecimal seems too dangerous |
348 |
|
template <> |
349 |
|
std::string Represent::input(const Item& item) |
350 |
|
{ |
351 |
|
return item.data; |
352 |
|
} |
353 |
|
|
354 |
< |
// XXX: constructing a string from Binary or Hexadecimal seems to dangerous |
354 |
> |
// XXX: constructing a string from Binary or Hexadecimal seems too dangerous |
355 |
|
template <> |
356 |
|
ext::String Represent::input(const Item& item) |
357 |
|
{ |