-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathxmime_internal.hpp
67 lines (53 loc) · 2.04 KB
/
xmime_internal.hpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/************************************************************************************
* Copyright (c) 2016, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht *
* Copyright (c) 2016, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
************************************************************************************/
#ifndef XCPP_MIME_INTERNAL_HPP
#define XCPP_MIME_INTERNAL_HPP
#include <cstddef>
#include <locale>
#include <string>
#include "clang/Interpreter/CppInterOp.h" // from CppInterOp package
#include <nlohmann/json.hpp>
namespace nl = nlohmann;
namespace xcpp
{
inline nl::json mime_repr(intptr_t V)
{
// Return a JSON mime bundle representing the specified value.
void* value_ptr = reinterpret_cast<void*>(V);
// Include "xcpp/xmime.hpp" only on the first time a variable is displayed.
static bool xmime_included = false;
if (!xmime_included)
{
Cpp::Declare("#include \"xcpp/xmime.hpp\"");
xmime_included = true;
}
intptr_t mimeReprV;
bool hadError = false;
{
std::ostringstream code;
code << "using xcpp::mime_bundle_repr;";
code << "mime_bundle_repr(";
// code << "*(" << getTypeAsString(V);
code << &value_ptr;
code << "));";
std::string codeString = code.str();
mimeReprV = Cpp::Evaluate(codeString.c_str(), &hadError);
}
void* mimeReprV_ptr = reinterpret_cast<void*>(V);
if (!hadError && mimeReprV_ptr)
{
return *(nl::json*) mimeReprV_ptr;
}
else
{
return nl::json::object();
}
}
}
#endif