core/vnl/vnl_matlab_print_format.cxx
Go to the documentation of this file.
00001 // This is core/vnl/vnl_matlab_print_format.cxx
00002 #include "vnl_matlab_print_format.h"
00003 //:
00004 // \file
00005 
00006 #include <vcl_iostream.h>
00007 #include <vcl_vector.h>
00008 
00009 //: Choose precision in printouts.
00010 //
00011 // vnl_matlab_format(vnl_matops::fmt_long) selects 16-digit precision
00012 //
00013 // vnl_matlab_format(vnl_matops::fmt_short) selects 4-digit precision
00014 
00015 //: this variable is the current top of the stack.
00016 // moved here because gcc 2.7 choked
00017 static vnl_matlab_print_format the_format = vnl_matlab_print_format_short;
00018 //: the rest of the stack is stored in this vector.
00019 static vcl_vector<int> *format_stack = 0;
00020 //: call this to initialize the format stack.
00021 static void vnl_matlab_print_format_init()
00022 { if (!format_stack) format_stack = new vcl_vector<int>; }
00023 
00024 void vnl_matlab_print_format_push(vnl_matlab_print_format f)
00025 {
00026   vnl_matlab_print_format_init();
00027   format_stack->push_back(the_format);
00028   the_format = f;
00029 }
00030 
00031 void vnl_matlab_print_format_pop()
00032 {
00033   vnl_matlab_print_format_init();
00034   if (format_stack->empty())
00035     vcl_cerr << __FILE__ ": format stack empty\n";
00036   else {
00037     the_format = vnl_matlab_print_format(format_stack->back());
00038     format_stack->pop_back();
00039   }
00040 }
00041 
00042 vnl_matlab_print_format vnl_matlab_print_format_set(vnl_matlab_print_format f)
00043 {
00044   vnl_matlab_print_format_init();
00045   vnl_matlab_print_format old = the_format;
00046   the_format = f;
00047   return old;
00048 }
00049 
00050 vnl_matlab_print_format vnl_matlab_print_format_top()
00051 {
00052   return the_format;
00053 }