PLearn 0.1
Public Member Functions | Static Public Member Functions | Private Attributes
PLearn::ShellProgressBar Class Reference

#include <ShellProgressBar.h>

Collaboration diagram for PLearn::ShellProgressBar:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ShellProgressBar ()
 ShellProgressBar (int min, int max, string caption="", int width=10)
void init ()
void draw (bool simple_mode=false)
bool update (int value)
void reset ()
void set (int min, int max, string caption="", int w=10)
void setCaption (string caption)
void setMin (int min)
void setMax (int max)
void done ()

Static Public Member Functions

static string getTime ()
static int getAsciiFileLineCount (string file)
static int getWcAsciiFileLineCount (string file)

Private Attributes

int min
int max
real blockwidth
int pos
string caption
int width
bool max_reached

Detailed Description

Definition at line 74 of file ShellProgressBar.h.


Constructor & Destructor Documentation

PLearn::ShellProgressBar::ShellProgressBar ( ) [inline]

Definition at line 79 of file ShellProgressBar.h.

: min(0), max(0), caption(""), width(10) {}
PLearn::ShellProgressBar::ShellProgressBar ( int  min,
int  max,
string  caption = "",
int  width = 10 
)

Definition at line 47 of file ShellProgressBar.cc.

References init().

    : min(min), max(max), caption(caption), width(width)
{
    init();
}

Here is the call graph for this function:


Member Function Documentation

void PLearn::ShellProgressBar::done ( )

Definition at line 127 of file ShellProgressBar.cc.

References PLearn::endl(), getTime(), max, max_reached, and update().

Referenced by PLearn::WordNetOntology::extract(), PLearn::GraphicalBiText::init(), PLearn::WordNetOntology::load(), PLearn::GraphicalBiText::loadBitext(), main(), PLearn::GraphicalBiText::print(), and PLearn::GraphicalBiText::test_WSD().

{
    if (!max_reached)
        update(max);
    cout << "\033[2C" << getTime() << endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ShellProgressBar::draw ( bool  simple_mode = false)

Definition at line 60 of file ShellProgressBar.cc.

References caption, getTime(), i, PLearn::tostring(), and width.

Referenced by PLearn::WordNetOntology::extract(), PLearn::WordNetOntology::extractTaggedWordFrequencies(), PLearn::GraphicalBiText::init(), PLearn::WordNetOntology::load(), PLearn::GraphicalBiText::loadBitext(), PLearn::loadToVMat(), main(), PLearn::GraphicalBiText::print(), and PLearn::GraphicalBiText::test_WSD().

{
    if (simple_mode)
    {
        cout << caption << " " << getTime() << " ";
        cout.flush();
    } else
    {
        cout << caption << " " << getTime() << " |";
        for (int i = 0;i < width; i++) cout << " ";
        cout <<"|";
        string move_cursor_left = "\033[" + tostring(width + 1) + "D";
        cout << move_cursor_left;
        cout.flush();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PLearn::ShellProgressBar::getAsciiFileLineCount ( string  file) [static]

Definition at line 134 of file ShellProgressBar.cc.

References in, and PLearn::pgetline().

Referenced by PLearn::WordNetOntology::extract(), PLearn::WordNetOntology::load(), and PLearn::GraphicalBiText::loadBitext().

{
    // not terribly efficient, I fear, but I don't 
    // have the time for a better solution (the one
    // with Popen crashes with a MPI program...)
    ifstream in(file.c_str());
    int n_lines = 0;
    while (in)
    {
        pgetline(in);
        n_lines++;
    }
    in.close();
    return n_lines;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::ShellProgressBar::getTime ( ) [static]

Definition at line 157 of file ShellProgressBar.cc.

References PLearn::split().

Referenced by done(), and draw().

{
    time_t tt;
    time(&tt);
    string time_str(ctime(&tt));
    vector<string> tokens = split(time_str);
    return "[" + tokens[3] + "]";
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PLearn::ShellProgressBar::getWcAsciiFileLineCount ( string  file) [static]

Definition at line 150 of file ShellProgressBar.cc.

References PLearn::execute(), and PLearn::toint().

Referenced by extractFiles(), and main().

{
    string wc = "wc -l " + file;
    vector<string> answer = execute(wc);
    return toint(answer[0]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ShellProgressBar::init ( )
void PLearn::ShellProgressBar::reset ( )

Definition at line 106 of file ShellProgressBar.cc.

References max_reached, and pos.

Referenced by main().

{
    max_reached = false;
    pos = 0;
}

Here is the caller graph for this function:

void PLearn::ShellProgressBar::set ( int  min,
int  max,
string  caption = "",
int  w = 10 
) [inline]

Definition at line 89 of file ShellProgressBar.h.

References PLearn::max(), PLearn::min(), and w.

Referenced by PLearn::GraphicalBiText::init(), PLearn::GraphicalBiText::loadBitext(), main(), and PLearn::GraphicalBiText::test_WSD().

{ setMin(min); setMax(max); setCaption(caption); width = w; }

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ShellProgressBar::setCaption ( string  caption)

Definition at line 112 of file ShellProgressBar.cc.

References caption.

{
    caption = the_caption;
}
void PLearn::ShellProgressBar::setMax ( int  max)

Definition at line 122 of file ShellProgressBar.cc.

References max.

{
    max = the_max;
}
void PLearn::ShellProgressBar::setMin ( int  min)

Definition at line 117 of file ShellProgressBar.cc.

References min.

{
    min = the_min;
}
bool PLearn::ShellProgressBar::update ( int  value)

Definition at line 77 of file ShellProgressBar.cc.

References blockwidth, i, max, max_reached, min, pos, and width.

Referenced by done(), PLearn::WordNetOntology::extract(), PLearn::GraphicalBiText::init(), PLearn::WordNetOntology::load(), PLearn::GraphicalBiText::loadBitext(), main(), PLearn::GraphicalBiText::print(), and PLearn::GraphicalBiText::test_WSD().

{
    if (value < min || max_reached)
    {
        return false;
    } else if (value >= max)
    {
        for (int i = pos; i < width; i++)
        {
            cout << "=";
            cout.flush();
        }
        max_reached = true;
        return true;
    }

    int inc = (int)((value - min) / blockwidth);

    int i;
    for (i = pos; i < inc; i++)
    {
        cout << "=";
        cout.flush();
    }
    pos = i;

    return true;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 102 of file ShellProgressBar.h.

Referenced by init(), and update().

Definition at line 104 of file ShellProgressBar.h.

Referenced by draw(), and setCaption().

Definition at line 101 of file ShellProgressBar.h.

Referenced by done(), init(), setMax(), and update().

Definition at line 106 of file ShellProgressBar.h.

Referenced by done(), init(), reset(), and update().

Definition at line 100 of file ShellProgressBar.h.

Referenced by init(), setMin(), and update().

Definition at line 103 of file ShellProgressBar.h.

Referenced by init(), reset(), and update().

Definition at line 105 of file ShellProgressBar.h.

Referenced by draw(), init(), and update().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines