Voreen - Volume Rendering Engine Voreen - Volume Rendering Engine
Voreen - Volume Rendering Engine Westfälische Wilhelms-Universität Münster
  • About
  • Gallery
  • Download
  • Documentation
  • Publications
  • Community

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List

include/voreen/core/utils/cmdparser/singlecommand.h

00001 /**********************************************************************
00002  *                                                                    *
00003  * Voreen - The Volume Rendering Engine                               *
00004  *                                                                    *
00005  * Copyright (C) 2005-2010 The Voreen Team. <http://www.voreen.org>   *
00006  *                                                                    *
00007  * This file is part of the Voreen software package. Voreen is free   *
00008  * software: you can redistribute it and/or modify it under the terms *
00009  * of the GNU General Public License version 2 as published by the    *
00010  * Free Software Foundation.                                          *
00011  *                                                                    *
00012  * Voreen is distributed in the hope that it will be useful,          *
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
00015  * GNU General Public License for more details.                       *
00016  *                                                                    *
00017  * You should have received a copy of the GNU General Public License  *
00018  * in the file "LICENSE.txt" along with this program.                 *
00019  * If not, see <http://www.gnu.org/licenses/>.                        *
00020  *                                                                    *
00021  * The authors reserve all rights not expressly granted herein. For   *
00022  * non-commercial academic use see the license exception specified in *
00023  * the file "LICENSE-academic.txt". To get information about          *
00024  * commercial licensing please contact the authors.                   *
00025  *                                                                    *
00026  **********************************************************************/
00027 
00028 #ifndef VRN_SINGLECOMMAND_H
00029 #define VRN_SINGLECOMMAND_H
00030 
00031 #include "voreen/core/utils/cmdparser/command.h"
00032 
00033 namespace voreen {
00034 
00042 template<class T, class U = T, class V = U, class W = V>
00043 class SingleCommand : public Command {
00044 public:
00045     SingleCommand(T* ptr1,
00046         const std::string& name, const std::string& shortName = "", const std::string& infoText = "",
00047         const std::string parameterList = "")
00048         : Command(name, shortName, infoText, parameterList, 1, false)
00049         , ptr1_(ptr1)
00050         , ptr2_(0)
00051         , ptr3_(0)
00052         , ptr4_(0)
00053     {}
00054 
00055     SingleCommand(T* ptr1, U* ptr2,
00056         const std::string& name, const std::string& shortName = "", const std::string& infoText = "",
00057         const std::string parameterList = "")
00058         : Command(name, shortName, infoText, parameterList, 2, false)
00059         , ptr1_(ptr1)
00060         , ptr2_(ptr2)
00061         , ptr3_(0)
00062         , ptr4_(0)
00063     {}
00064 
00065     SingleCommand(T* ptr1, U* ptr2, V* ptr3,
00066         const std::string& name, const std::string& shortName = "", const std::string& infoText = "",
00067         const std::string parameterList = "")
00068         : Command(name, shortName, infoText, parameterList, 3, false)
00069         , ptr1_(ptr1)
00070         , ptr2_(ptr2)
00071         , ptr3_(ptr3)
00072         , ptr4_(0)
00073     {}
00074 
00075     SingleCommand(T* ptr1, U* ptr2, V* ptr3, W* ptr4,
00076         const std::string& name, const std::string& shortName = "", const std::string& infoText = "",
00077         const std::string parameterList = "")
00078         : Command(name, shortName, infoText, parameterList, 4, false)
00079         , ptr1_(ptr1)
00080         , ptr2_(ptr2)
00081         , ptr3_(ptr3)
00082         , ptr4_(ptr4)
00083     {}
00084 
00085     ~SingleCommand() {}
00086     bool execute(const std::vector<std::string>& parameters) {
00087         *ptr1_ = cast<T>(parameters[0]);
00088         if (ptr2_ != 0)
00089             *ptr2_ = cast<U>(parameters[1]);
00090         if (ptr3_ != 0)
00091             *ptr3_ = cast<V>(parameters[2]);
00092         if (ptr4_ != 0)
00093             *ptr4_ = cast<W>(parameters[3]);
00094 
00095         return true;
00096     }
00097 
00098     bool checkParameters(const std::vector<std::string>& parameters) {
00099         bool result = parameters.size() == static_cast<size_t>(argumentNum_);
00100 
00101         result &= is<T>(parameters[0]);
00102         if (ptr2_ != 0)
00103             result &= is<U>(parameters[1]);
00104         if (ptr3_ != 0)
00105             result &= is<V>(parameters[2]);
00106         if (ptr4_ != 0)
00107             result &= is<W>(parameters[3]);
00108 
00109         return result;
00110     }
00111 
00112 protected:
00113     T* ptr1_;
00114     U* ptr2_;
00115     V* ptr3_;
00116     W* ptr4_;
00117 };
00118 
00119 
00126 class SingleCommandZeroArguments : public Command {
00127 public:
00128     SingleCommandZeroArguments(bool* ptr, const std::string& name, const std::string& shortName = "",
00129         const std::string& infoText = "")
00130         : Command(name, shortName, infoText, "", 0, false)
00131         , ptr_(ptr)
00132     {}
00133 
00134     bool execute(const std::vector<std::string>& /*parameters*/) {
00135         *ptr_ = true;
00136         return true;
00137     }
00138 
00139 protected:
00140     bool* ptr_;
00141 };
00142 
00143 } // namespace
00144 
00145 #endif // VRN_SINGLECOMMAND_H
  • Getting Started
  • Video Tutorials
  • Build Instructions
  • Adding a Module
  • Programming Tutorials
  • API Documentation
  • FAQ
edit