OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librtcltools/] [RtclStats.cpp] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 wfjm
// $Id: RtclStats.cpp 495 2013-03-06 17:13:48Z mueller $
2 10 wfjm
//
3 19 wfjm
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 10 wfjm
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16 19 wfjm
// 2013-03-06   495   1.0.1  Rename Exec->Collect
17 10 wfjm
// 2011-02-26   364   1.0    Initial version
18
// 2011-02-20   363   0.1    First draft
19
// ---------------------------------------------------------------------------
20
 
21
/*!
22
  \file
23 19 wfjm
  \version $Id: RtclStats.cpp 495 2013-03-06 17:13:48Z mueller $
24 10 wfjm
  \brief   Implemenation of RtclStats.
25
*/
26
 
27
#include <sstream>
28
 
29
#include "RtclStats.hpp"
30
#include "RtclNameSet.hpp"
31
#include "RtclOPtr.hpp"
32
 
33
using namespace std;
34
 
35 19 wfjm
/*!
36
  \class Retro::RtclStats
37
  \brief FIXME_docs
38
*/
39
 
40
// all method definitions in namespace Retro
41
namespace Retro {
42
 
43 10 wfjm
//------------------------------------------+-----------------------------------
44
//! FIXME_docs
45
 
46
bool RtclStats::GetArgs(RtclArgs& args, Context& cntx)
47
{
48
  static RtclNameSet optset("-lname|-ltext|-lvalue|-lpair|-lall|"
49
                            "-atext|-avalue|-print");
50
 
51
  string opt;
52
  string varname;
53
  string format;
54
  int    width=0;
55
  int    prec=0;
56
 
57
  if (args.NextOpt(opt, optset)) {
58
    if (opt == "-atext" || opt == "-avalue") {
59
      if (!args.GetArg("varName", varname)) return false;
60
    } else if (opt == "-print") {
61
      if (!args.GetArg("?format", format)) return false;
62
      if (!args.GetArg("?width", width, 0, 32)) return false;
63
      if (!args.GetArg("?prec",  prec,  0, 32)) return false;
64
    }
65
 
66
  } else {
67
    opt   = "-print";
68
    width = 12;
69
  }
70
  if (!args.AllDone()) return false;
71
 
72
  cntx.opt     = opt;
73
  cntx.varname = varname;
74
  cntx.format  = format;
75
  cntx.width   = width;
76
  cntx.prec    = prec;
77
 
78
  return true;
79
}
80
 
81
//------------------------------------------+-----------------------------------
82
//! FIXME_docs
83
 
84 19 wfjm
bool RtclStats::Collect(RtclArgs& args, const Context& cntx,
85
                        const Rstats& stats)
86 10 wfjm
{
87
  Tcl_Interp* interp = args.Interp();
88
  Tcl_Obj*    plist   = Tcl_GetObjResult(interp);
89
 
90
  if        (cntx.opt == "-lname") {        // -lname -------------------------
91
    for (size_t i=0; i<stats.Size(); i++) {
92
      const string& name(stats.Name(i));
93
      RtclOPtr pobj(Tcl_NewStringObj(name.data(), name.length()));
94
      if (Tcl_ListObjAppendElement(interp, plist, pobj) != TCL_OK) return false;
95
    }
96
 
97
  } else if (cntx.opt == "-ltext") {        // -ltext -------------------------
98
    for (size_t i=0; i<stats.Size(); i++) {
99
      const string& text(stats.Text(i));
100
      RtclOPtr pobj(Tcl_NewStringObj(text.data(), text.length()));
101
      if (Tcl_ListObjAppendElement(interp, plist, pobj) != TCL_OK) return false;
102
    }
103
 
104
  } else if (cntx.opt == "-lvalue") {
105
    for (size_t i=0; i<stats.Size(); i++) { // -lvalue ------------------------
106
      RtclOPtr pobj(Tcl_NewDoubleObj(stats.Value(i)));
107
      if (Tcl_ListObjAppendElement(interp, plist, pobj) != TCL_OK) return false;
108
    }
109
 
110
  } else if (cntx.opt == "-lpair" || cntx.opt == "-lall") { // -lpair -lall ---
111
    for (size_t i=0; i<stats.Size(); i++) {
112
      const string& name(stats.Name(i));
113
      RtclOPtr ptup(Tcl_NewListObj(0,0));
114
      Tcl_ListObjAppendElement(NULL, ptup,
115
                               Tcl_NewDoubleObj(stats.Value(i)));
116
      Tcl_ListObjAppendElement(NULL, ptup,
117
                               Tcl_NewStringObj(name.data(), name.length()));
118
      if (cntx.opt == "-lall") {
119
        const string& text(stats.Text(i));
120
        Tcl_ListObjAppendElement(NULL, ptup,
121
                                 Tcl_NewStringObj(text.data(), text.length()));
122
      }
123
      if (Tcl_ListObjAppendElement(interp, plist, ptup) != TCL_OK) return false;
124
    }
125
 
126
  } else if (cntx.opt == "-atext") {        // -atext -------------------------
127
    for (size_t i=0; i<stats.Size(); i++) {
128
      const string& text(stats.Text(i));
129
      RtclOPtr pobj(Tcl_NewStringObj(text.data(), text.length()));
130
      if (!Tcl_SetVar2Ex(interp, cntx.varname.c_str(), stats.Name(i).c_str(),
131
                         pobj, TCL_LEAVE_ERR_MSG)) return false;
132
    }
133
 
134
  } else if (cntx.opt == "-avalue") {       // -avalue ------------------------
135
    for (size_t i=0; i<stats.Size(); i++) {
136
      RtclOPtr pobj(Tcl_NewDoubleObj(stats.Value(i)));
137
      if (!Tcl_SetVar2Ex(interp, cntx.varname.c_str(), stats.Name(i).c_str(),
138
                         pobj, TCL_LEAVE_ERR_MSG)) return false;
139
    }
140
 
141
  } else if (cntx.opt == "-print") {        // -print -------------------------
142
    ostringstream sos;
143
    stats.Print(sos, cntx.format.c_str(), cntx.width, cntx.prec);
144
    args.AppendResultLines(sos);
145
 
146
  } else {
147 19 wfjm
    args.AppendResult("-E: BUG! RtclStats::Collect: bad option '",
148
                      cntx.opt.c_str(), "'", NULL);
149 10 wfjm
    return false;
150
  }
151
 
152
  return true;
153
}
154
 
155 19 wfjm
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.