ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cppmagic.py
Go to the documentation of this file.
1 # -*- coding:utf-8 -*-
2 #-----------------------------------------------------------------------------
3 # Copyright (c) 2015, ROOT Team.
4 # Authors: Omar Zapata <Omar.Zapata@cern.ch> http://oproject.org
5 # Danilo Piparo <Danilo.Piparo@cern.ch> CERN
6 # Enric Tejedor enric.tejedor.saavedra@cern.ch> CERN
7 # website: http://oproject.org/ROOT+Jupyter+Kernel (information only for ROOT kernel)
8 # Distributed under the terms of the Modified LGPLv3 License.
9 #
10 # The full license is in the file COPYING.rst, distributed with this software.
11 #-----------------------------------------------------------------------------
12 from metakernel import Magic, option
13 
14 import sys
15 
16 #NOTE:actually JupyROOT is not capturing the error on %%cpp -d if the function is wrong
17 class CppMagics(Magic):
18  def __init__(self, kernel):
19  super(CppMagics, self).__init__(kernel)
20  @option(
21  '-a', '--aclic', action='store', default="default", help='Compile code with ACLiC.'
22  )
23  @option(
24  '-d', '--declare', action='store', default=None, help='Declare functions and/or classes.'
25  )
26  def cell_cpp(self, args):
27  '''Executes the content of the cell as C++ code.'''
28  if self.code.strip():
29  self.kernel.ioHandler.clear()
30  self.kernel.ioHandler.InitCapture()
31 
32  if args=='-a':
33  self.kernel.ACLiC(self.code)
34  elif args=='-d':
35  self.kernel.Declarer(str(self.code))
36  else:
37  self.kernel.Executor(str(self.code))
38  self.kernel.ioHandler.EndCapture()
39  std_out = self.kernel.ioHandler.getStdout()
40  std_err = self.kernel.ioHandler.getStderr()
41  if std_out != "":
42  stream_content_stdout = {'name': 'stdout', 'text': std_out}
43  self.kernel.send_response(self.kernel.iopub_socket, 'stream', stream_content_stdout)
44  if std_err != "":
45  stream_content_stderr = {'name': 'stderr', 'text': std_err}
46  self.kernel.send_response(self.kernel.iopub_socket, 'stream', stream_content_stderr)
47 
48  self.evaluate = False
49 
50 def register_magics(kernel):
51  kernel.register_magics(CppMagics)
52