OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimStdOutProgress.cpp
Go to the documentation of this file.
1 //---
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: MIT
5 //
6 // Author: Garrett Potts
7 //
8 //---
9 // $Id$
10 
13 #include <iomanip>
14 
15 #if defined(WIN32) || defined(_MSC_VER) && !defined(__CYGWIN__) && !defined(__MWERKS__)
16  #include <io.h>
17  #define ISATTY _isatty
18  #define FILENO _fileno
19 #else
20  #include <unistd.h>
21  #define ISATTY isatty
22  #define FILENO fileno
23 #endif
24 
25 RTTI_DEF1(ossimStdOutProgress, "ossimStdOutProgress", ossimProcessListener);
26 
28 
30  bool flushStream)
31  :
33  thePrecision(precision),
34  theFlushStreamFlag(flushStream),
35  theRunningInConsoleFlag(true)
36 {
37  // Determine if running in a terminal window. Progress reports are only written to console if
38  // running in one.
39 
40  ossimString stdOutConsole;
41  stdOutConsole = ossimPreferences::instance()->findPreference("ossim.std.out.progress");
42 
43  if ( stdOutConsole.size() )
44  {
45  // Override auto detected console.
46  theRunningInConsoleFlag = stdOutConsole.toBool();
47  }
48  else if ( !ISATTY(FILENO(stdout) ) )
49  {
51  }
52 }
53 
55 {
57  return;
58 
59  if (event.getOutputMessageFlag())
60  {
61  ossimString s;
62  event.getMessage(s);
63  if (!s.empty())
64  {
65  ossimNotify(ossimNotifyLevel_NOTICE) << s.c_str() << std::endl;
66  }
67  return; // Don't output percentage on a message update.
68  }
69 
70  double p = event.getPercentComplete();
72  << std::setiosflags(std::ios::fixed)
73  << std::setprecision(thePrecision)
74  << p << "%\r";
75 
77  {
78  (p != 100.0) ?
81  }
82 }
83 
85 {
86  theFlushStreamFlag = flag;
87 }
88 
ossimStdOutProgress theStdOutProgress
RTTI_DEF1(ossimStdOutProgress, "ossimStdOutProgress", ossimProcessListener)
virtual void processProgressEvent(ossimProcessProgressEvent &event)
#define ISATTY
const char * findPreference(const char *key) const
std::string::size_type size() const
Definition: ossimString.h:405
bool toBool() const
String to numeric methods.
virtual void setFlushStreamFlag(bool flag)
unsigned int ossim_uint32
ossimStdOutProgress(ossim_uint32 precision=0, bool flushStream=false)
static ossimPreferences * instance()
#define FILENO
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)