Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

OptionParams.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "OptionParams.h"
00010 
00011 #include "Log.h"
00012 #include "Environ.h"
00013 
00014 //-----------------------------------------------------------------
00015 void
00016 OptionParams::addParam(const std::string &name, eType type,
00017         const std::string &help)
00018 {
00019     Param param(type, help);
00020     m_params.insert(
00021                 std::pair<std::string,Param>(name, param));
00022     int paramSize = name.size() + getType(type).size();
00023     if (paramSize > m_maxSize) {
00024         m_maxSize = paramSize;
00025     }
00026 }
00027 //-----------------------------------------------------------------
00028 std::string
00029 OptionParams::getHelp(const Environ * /*options*/) const
00030 {
00031     std::string help;
00032     t_params::const_iterator end = m_params.end();
00033     for (t_params::const_iterator i = m_params.begin(); i != end; ++i) {
00034         int paramSize = i->first.size() + getType(i->second.type).size();
00035         std::string space = std::string(m_maxSize - paramSize, ' ');
00036         help += "  " + i->first + "=<" + getType(i->second.type) + ">";
00037         help += space + "    " + i->second.help + "\n";
00038     }
00039     return help;
00040 }
00041 //-----------------------------------------------------------------
00042 std::string
00043 OptionParams::getConfig(const Environ *options) const
00044 {
00045     std::string config;
00046     t_params::const_iterator end = m_params.end();
00047     for (t_params::const_iterator i = m_params.begin(); i != end; ++i) {
00048         config += i->first + "='" + options->getParam(i->first) + "'\n";
00049     }
00050     return config;
00051 }
00052 //-----------------------------------------------------------------
00053 std::string
00054 OptionParams::getType(eType type) const
00055 {
00056     switch (type) {
00057         case TYPE_NUMBER:
00058             return "number";
00059         case TYPE_BOOLEAN:
00060             return "boolean";
00061         case TYPE_STRING:
00062             return "string";
00063         case TYPE_PATH:
00064             return "path";
00065         default:
00066             LOG_WARNING(ExInfo("unknown param type")
00067                     .addInfo("type", type));
00068     }
00069     return "unknown";
00070 }
00071 
00072 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2