CppADCodeGen  2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
dot_util.hpp
1 #ifndef CPPAD_CG_DOT_UTIL_INCLUDED
2 #define CPPAD_CG_DOT_UTIL_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2016 Ciengis
6  *
7  * CppADCodeGen is distributed under multiple licenses:
8  *
9  * - Eclipse Public License Version 1.0 (EPL1), and
10  * - GNU General Public License Version 3 (GPL3).
11  *
12  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14  * ----------------------------------------------------------------------------
15  * Author: Joao Leal
16  */
17 
18 #include <cppad/cg/lang/c/lang_c_default_var_name_gen.hpp>
19 
20 namespace CppAD {
21 namespace cg {
22 
26 template<class Base>
27 inline void printDotExpression(CG<Base>& dep,
28  std::ostream& out = std::cout) {
29  if (dep.getOperationNode() != nullptr) {
30  if (dep.getOperationNode()->getCodeHandler() == nullptr) {
31  throw CGException("Unable to print expression: found an operation node without a CodeHandler!");
32  }
33 
34  CodeHandler<Base>& handler = *dep.getOperationNode()->getCodeHandler();
35  LanguageDot<double> langDot;
36  LangCDefaultVariableNameGenerator<double> nameGen;
37 
38  std::vector<CG<Base> > depv(1);
39  depv[0] = dep;
40 
41  std::ostringstream code;
42  handler.generateCode(code, langDot, depv, nameGen);
43  out << code.str();
44  } else {
45  out << "digraph {\n"
46  "\"" << dep.getValue() << "\" -> \"y[0]\"\n"
47  "}" << std::endl;
48  }
49 }
50 
51 template<class Base>
52 inline void printDotExpression(OperationNode<Base>& dep,
53  std::ostream& out = std::cout) {
54  printDotExpression(CG<Base>(dep), out);
55 }
56 
57 }
58 }
59 
60 #endif