26 #if defined (HAVE_CONFIG_H)
47 const std::list<whos_parameter>& params)
const
51 auto i = params.begin ();
55 while (i != params.end ())
66 os << std::setiosflags (std::ios::left)
71 os << std::setiosflags (std::ios::right)
79 - dims_str.find (
'x');
83 front = (front > 0) ? front : 0;
84 back = (back > 0) ? back : 0;
86 os << std::setiosflags (std::ios::left)
89 << std::resetiosflags (std::ios::left)
91 << std::setiosflags (std::ios::left)
94 << std::resetiosflags (std::ios::left);
98 os << std::setiosflags (std::ios::left)
104 error (
"whos_line_format: modifier '%c' unknown",
114 tmp[0] = (m_is_complex ?
'c' :
' ');
115 tmp[1] = (m_is_sparse ?
's' :
' ');
116 tmp[2] = (m_is_formal ?
'f' :
' ');
117 tmp[3] = (m_is_global ?
'g' :
' ');
118 tmp[4] = (m_is_persistent ?
'p' :
' ');
134 os << m_value.
numel ();
151 error (
"whos_line_format: command '%c' unknown",
155 os << std::resetiosflags (std::ios::left)
156 << std::resetiosflags (std::ios::right);
172 for (
const auto& syminfo :
m_lst)
174 if (name == syminfo.name ())
175 return syminfo.value ();
181 std::list<std::string>
184 std::list<std::string> retval;
186 for (
const auto& syminfo :
m_lst)
187 retval.push_back (syminfo.name ());
194 int nesting_level)
const
210 for (
const auto& syminfo :
m_lst)
214 ni.
assign (
"function", caller_function_name);
215 ni.
assign (
"level", nesting_level);
217 name_info(j) = syminfo.name ();
218 global_info(j) = syminfo.is_global ();
219 persistent_info(j) = syminfo.is_persistent ();
223 size_info(j) = val.
size ();
228 nesting_info(j) = ni;
235 info.
assign (
"name", name_info);
236 info.
assign (
"size", size_info);
237 info.
assign (
"bytes", bytes_info);
238 info.
assign (
"class", class_info);
239 info.
assign (
"global", global_info);
240 info.
assign (
"sparse", sparse_info);
241 info.
assign (
"complex", complex_info);
242 info.
assign (
"nesting", nesting_info);
243 info.
assign (
"persistent", persistent_info);
250 const std::list<whos_parameter> params)
const
252 std::ostringstream param_buf;
256 for (
const auto& param : params)
258 if (param.command !=
'\0')
261 switch (param.modifier)
264 os << std::setiosflags (std::ios::left)
265 << std::setw (param.parameter_length);
266 param_buf << std::setiosflags (std::ios::left)
267 << std::setw (param.parameter_length);
271 os << std::setiosflags (std::ios::right)
272 << std::setw (param.parameter_length);
273 param_buf << std::setiosflags (std::ios::right)
274 << std::setw (param.parameter_length);
278 if (param.command !=
's')
280 os << std::setiosflags (std::ios::left)
281 << std::setw (param.parameter_length);
282 param_buf << std::setiosflags (std::ios::left)
283 << std::setw (param.parameter_length);
288 os << std::setiosflags (std::ios::left)
289 << std::setw (param.parameter_length);
290 param_buf << std::setiosflags (std::ios::left)
291 << std::setw (param.parameter_length);
294 if (param.command ==
's' && param.modifier ==
'c')
296 int a = param.first_parameter_length - param.balance;
298 int b = param.parameter_length - a - param.text.length ();
300 os << std::setiosflags (std::ios::left) << std::setw (a)
301 <<
"" << std::resetiosflags (std::ios::left) << param.text
302 << std::setiosflags (std::ios::left)
303 << std::setw (b) <<
""
304 << std::resetiosflags (std::ios::left);
305 param_buf << std::setiosflags (std::ios::left)
307 <<
"" << std::resetiosflags (std::ios::left)
309 << std::setiosflags (std::ios::left)
310 << std::setw (b) <<
""
311 << std::resetiosflags (std::ios::left);
316 param_buf << param.line;
318 os << std::resetiosflags (std::ios::left)
319 << std::resetiosflags (std::ios::right);
320 param_buf << std::resetiosflags (std::ios::left)
321 << std::resetiosflags (std::ios::right);
326 param_buf << param.line;
330 os << param_buf.str ();
335 const std::string&
format)
const
337 if (!
m_lst.empty ())
339 std::size_t bytes = 0;
340 std::size_t elements = 0;
348 for (
const auto& syminfo :
m_lst)
350 syminfo.display_line (os, params);
354 elements += val.
numel ();
358 os <<
"\nTotal is " << elements
359 << (elements == 1 ?
" element" :
" elements")
360 <<
" using " << bytes << (bytes == 1 ?
" byte" :
" bytes")
365 std::list<whos_parameter>
369 std::size_t format_len =
format.length ();
371 std::list<whos_parameter> params;
376 std::string param_string =
"abcenst";
379 std::size_t pos_a, pos_b, pos_c, pos_e, pos_n, pos_s, pos_t;
381 pos_a = param_string.find (
'a');
382 pos_b = param_string.find (
'b');
383 pos_c = param_string.find (
'c');
384 pos_e = param_string.find (
'e');
385 pos_n = param_string.find (
'n');
386 pos_s = param_string.find (
's');
387 pos_t = param_string.find (
't');
389 param_names(pos_a) =
"Attr";
390 param_names(pos_b) =
"Bytes";
391 param_names(pos_c) =
"Class";
392 param_names(pos_e) =
"Elements";
393 param_names(pos_n) =
"Name";
394 param_names(pos_s) =
"Size";
395 param_names(pos_t) =
"Type";
397 for (std::size_t i = 0; i < param_string.length (); i++)
398 param_length(i) = param_names(i).length ();
401 param_length(pos_a) = 6;
406 for (
const auto& syminfo :
m_lst)
408 std::stringstream ss1, ss2;
411 str = syminfo.name ();
412 param_length(pos_n) = ((str.length ()
413 >
static_cast<std::size_t
> (param_length(pos_n)))
414 ? str.length () : param_length(pos_n));
419 param_length(pos_t) = ((str.length ()
420 >
static_cast<std::size_t
> (param_length(pos_t)))
421 ? str.length () : param_length(pos_t));
423 elements1 = val.
numel ();
426 param_length(pos_e) = ((str.length ()
427 >
static_cast<std::size_t
> (param_length(pos_e)))
428 ? str.length () : param_length(pos_e));
433 param_length(pos_b) = ((str.length ()
434 >
static_cast<std::size_t
> (param_length(pos_b)))
435 ? str.length () : param_length (pos_b));
439 while (
static_cast<std::size_t
> (idx) < format_len)
458 pos = cmd.find (
';');
459 if (pos == std::string::npos)
460 error (
"parameter without ; in format");
462 cmd = cmd.substr (0, pos+1);
464 idx += cmd.length ();
468 if (cmd.find_first_of (
"crl") != 1)
469 items = sscanf (cmd.c_str (),
"%c%c:%d:%d:%d;",
470 &garbage, ¶m.
command, &a, &b, &balance);
472 items = sscanf (cmd.c_str (),
"%c%c%c:%d:%d:%d;",
474 &a, &b, &balance) - 1;
477 error (
"whos_line_format: found parameter structure without command");
481 && param_string.find (param.
command) == std::string::npos)
489 pos = param_string.find (param.
command);
490 if (pos == std::string::npos)
491 error (
"whos_line_format: '%c' is not a command", param.
command);
494 param.
text = param_names(pos);
495 param.
line.assign (param_names(pos).
length (),
'=');
514 for (
const auto& syminfo :
m_lst)
518 int first1 = dims_str.find (
'x');
519 int total1 = dims_str.length ();
520 int rest1 = total1 - first1;
521 rest = (rest1 > rest ? rest1 : rest);
522 first = (first1 > first ? first1 : first);
523 total = (total1 > total ? total1 : total);
529 first += balance - first;
544 error (
"whos_line_format: modifier 'c' not available for command '%c'",
556 < param_length(pos_s)
557 ? param_length(pos_s)
560 params.push_back (param);
568 pos =
text.find (
'%');
569 if (pos != std::string::npos)
573 idx +=
text.length ();
575 param.
line.assign (
text.length (),
' ');
576 params.push_back (param);
583 OCTAVE_END_NAMESPACE(
octave)
std::size_t length() const
std::list< symbol_info > m_lst
Vector representing the dimensions (size) of an Array.
void assign(const std::string &k, const Cell &val)
void assign(const std::string &k, const octave_value &val)
std::string class_name() const
std::string get_dims_str() const
octave_idx_type numel() const
std::string type_name() const
std::size_t byte_size() const
void print_descriptor(std::ostream &os, const std::list< whos_parameter > params) const
std::list< std::string > names() const
void display(std::ostream &os, const std::string &format) const
std::list< whos_parameter > parse_whos_line_format(const std::string &format) const
octave_value varval(const std::string &name) const
octave_map map_value(const std::string &caller_function_name, int nesting_level) const
void display_line(std::ostream &os, const std::list< whos_parameter > ¶ms) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void() error(const char *fmt,...)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
int first_parameter_length
std::size_t format(std::ostream &os, const char *fmt,...)