
/****************************************************************************** 
 * 
 *  file:  VersionVisitor.h
 * 
 *  Copyright (c) 2003, Michael E. Smoot .
 *  All rights reverved.
 * 
 *  See the file COPYING in the top directory of this distribution for
 *  more information.
 *  
 *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 *  DEALINGS IN THE SOFTWARE.  
 *  
 *****************************************************************************/ 


#ifndef DtCmdLine_VERSION_VISITOR_H
#define DtCmdLine_VERSION_VISITOR_H
 
//! \file cmdVersionVisitor.h
//! \brief  This file declares the class DtCmdLine::VersionVisitor
//! \ingroup cmdLine

#include "cmdLineInterface.h"
#include "cmdLineOutput.h"
#include "cmdVisitor.h"

#include <vlutil/vlPrint.h>
#include <vlutil/vlKeyboard.h>
#include <vlutil/vlProcessControl.h>

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif

   namespace DtCmdLine {

      /**
       * A Vistor that will call the version method of the given CmdLineOutput
       * for the specified CmdLine object and then exit.
       */
      //! \ingroup cmdLine
      class VersionVisitor: public Visitor
      {
      protected:

         /**
          * The CmdLine of interest.
          */
         CmdLineInterface* _cmd;

         /**
          * The output object. 
          */
         CmdLineOutput** _out;

         bool myPressAnyKey;

      public:

         /**
          * Constructor.
          * \param cmd - The CmdLine the output is generated for. 
          * \param out - The type of output. 
          */
         VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out, 
#ifdef _WIN32
            bool pressAnyKey = true ) 
#else
            bool pressAnyKey = false ) 
#endif
            : Visitor(), _cmd( cmd ), _out( out ), myPressAnyKey(pressAnyKey) { }

         /**
          * Calls the version method of the output object using the
          * specified CmdLine.
          */
         virtual ~VersionVisitor() { }
         void visit(); 

      };

      inline void VersionVisitor::visit()
      {
         (*_out)->version(*_cmd);

         int oldNotifyLevel = DtNotifyLevel;
         DtNotifyLevel = 3;

         if (myPressAnyKey)
         {
            DtInfo("Press any key to continue\n");

            while (DtPollBlockingInputChar() == '\0')
            {
               DtSleep(0.1);
            }
         }

         DtNotifyLevel = oldNotifyLevel;

         exit(0);
      }

   }

#ifdef DtUSE_UTILITIES_NAMESPACE
}     //! end of namespace DtUSE_VLUTIL_NAMESPACE {
#endif

#endif
