Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TClingValue.cxx
Go to the documentation of this file.
1 // @(#)root/core/meta:$Id$
2 // Author: Vassil Vassilev 14/03/2013
3 
4 /*******************************************************************************
5 * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  ******************************************************************************/
11 
12 /** \class TClingValue
13 Bridge between cling::Value and ROOT.
14 */
15 
16 #include "TClingValue.h"
17 
18 #include "cling/Interpreter/Value.h"
19 #include "llvm/Support/raw_ostream.h"
20 
21 #include <cassert>
22 
23 TClingValue::TClingValue() {
24  // We default initialize to invalid value to keep a "sane" state.
25  assert(sizeof(fValue) >= sizeof(cling::Value)
26  && "sizeof(fValue) too small!");
27  new (&fValue) cling::Value();
28 }
29 
30 TClingValue::TClingValue(const TClingValue& Other):
31  TInterpreterValue() {
32  assert(sizeof(fValue) >= sizeof(cling::Value)
33  && "sizeof(fValue) too small!");
34  new (&fValue) cling::Value(Other.ToCV());
35 }
36 
37 TClingValue::~TClingValue() {
38  ToCV().~Value();
39 }
40 
41 TClingValue& TClingValue::operator=(TClingValue &Other) {
42  using namespace cling;
43  ToCV() = Other.ToCV();
44  return *this;
45 }
46 
47 std::pair<std::string, std::string> TClingValue::ToTypeAndValueString() const {
48  std::string output = ToString();
49  int paren_level = 0;
50 
51  for (size_t pos = 0; pos < output.size(); ++pos) {
52  if (output[pos] == '(')
53  ++paren_level;
54  else if (output[pos] == ')') {
55  --paren_level;
56  if (!paren_level)
57  return std::make_pair(output.substr(0, pos + 1), output.substr(pos + 2));
58  }
59  }
60 
61  return std::make_pair("", output);
62 }
63 
64 Bool_t TClingValue::IsValid() const {
65  return ToCV().isValid();
66 }
67 
68 Double_t TClingValue::GetAsDouble() const {
69  return ToCV().getDouble();
70 }
71 
72 Long_t TClingValue::GetAsLong() const {
73  return ToCV().getLL();
74 }
75 
76 ULong_t TClingValue::GetAsUnsignedLong() const {
77  return ToCV().getULL();
78 }
79 
80 void* TClingValue::GetAsPointer() const {
81  return ToCV().getPtr();
82 }
83 
84 std::string TClingValue::ToString() const {
85  std::string retVal;
86  llvm::raw_string_ostream ost(retVal);
87  ToCV().print(ost);
88  return ost.str();
89 }