summaryrefslogtreecommitdiff
path: root/Skin++/src/Cle2000.cxx
blob: c49b7219d89a58c40723bb63ea93848d00ab6a66 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

/*****************************************/
/*      C++ CLE-2000 OBJECT WRAPPER      */
/*    AUTHOR: A. HEBERT ; 2012/10/07     */
/*****************************************/

/*
Copyright (C) 2012 Ecole Polytechnique de Montreal

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/

#include "Cle2000.hxx"

using namespace std;
using namespace ganlib;
static ostringstream hsmg;

ganlib::Cle2000::Cle2000(string sname) {
  this->edit = 0;
  this->procName = sname;
  this->stack.reset();
}
ganlib::Cle2000::Cle2000(string sname, int_32 edit) {
  this->edit = edit;
  this->procName = sname;
  this->stack.reset();
}
ganlib::Cle2000::Cle2000(string sname, LifoPtr jstack) {
  this->edit = 0;
  this->procName = sname;
  this->stack = jstack;
}
ganlib::Cle2000::Cle2000(string sname, int_32 edit, LifoPtr jstack) {
  this->edit = edit;
  this->procName = sname;
  this->stack = jstack;
}

ganlib::Cle2000::~Cle2000() {
  cout << "Cle2000 destructor called." << endl;
}

void ganlib::Cle2000::setLifo(LifoPtr myLifo) {
  this->stack = myLifo;
}

void ganlib::Cle2000::exec() {
  int_32 ier, ilevel = 1;

// close the LCM objects
  for (int_32 ipos=0; ipos<this->stack->getMax(); ++ipos) {
    int_32 myTypeNode = this->stack->typeNode(ipos);
    if ((myTypeNode == 3) || (myTypeNode == 4)) {
      if (this->stack->accessNode(ipos) > 0) {
        ClcmPtr myClcm; this->stack->node(ipos, myClcm);
        try {
          lcm *myLcmStructure = myClcm->extract();
          lifo *myLifo = this->stack->extract();
          lifo_node *myNode = clepos(&myLifo, ipos);
          strcpy(myNode->OSname, myLcmStructure->hname);
          lcmcl_c(&myLcmStructure, 1);
        } catch(...) {
          throw Cle2000Exception("Exception catched by lcmcl_c");
        }
      }
    }
  }

// call the parametrized procedure
  try {
    ier = cle2000_c(ilevel, &donmod, (char *)this->procName.c_str(), this->edit,
                   (lifo*)this->stack->extract());
                   
  } catch(...) {
    throw Cle2000Exception("Exception catched by cle2000_c");
  }
  if (ier != 0) {
    hsmg << "Cle2000: cle2000 failure (" << this->procName << ".c2m). ier=" << ier;
    throw Cle2000Exception(hsmg.str());
  }

// reopen the LCM objects
  for (int ipos=0; ipos<this->stack->getMax(); ++ipos) {
    int_32 myTypeNode = this->stack->typeNode(ipos);
    if ((myTypeNode == 3) || (myTypeNode == 4)) {
      int_32 access = this->stack->accessNode(ipos);
      if (access == 0) access=1;
      ClcmPtr myClcm; this->stack->node(ipos, myClcm);
      try {
        lcm *myLcmStructure = myClcm->extract();
        int_32 myTypeNode = this->stack->typeNode(ipos);
        string myOSname_str = this->stack->OSName(ipos);
        char *myOSname = (char *)myOSname_str.c_str();
        lcmop_c(&myLcmStructure, myOSname, access, myTypeNode-2, 0);
      } catch(...) {
        throw Cle2000Exception("Exception catched by lcmop_c");
      }
    }
  }
}