Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Traits.cc

Go to the documentation of this file.
00001 // $Id: Traits.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "Traits.hh"
00027 #include "Traits.ih"
00028 
00029 // Custom includes
00030 #include <senf/Utils/senfassert.hh>
00031 
00032 //#include "Traits.mpp"
00033 #define prefix_
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 prefix_ long senf::console::detail::parseEnum(EnumTable const & table,
00037                                               ParseCommandInfo::TokensRange const & tokens)
00038 {
00039     if (tokens.size() != 1)
00040         throw SyntaxErrorException("parameter syntax error");
00041 
00042     std::string sym (tokens.begin()[0].value());
00043     boost::algorithm::to_lower(sym);
00044     EnumTable::left_map::const_iterator i1 (table.left.lower_bound(sym));
00045     EnumTable::left_map::const_iterator i2 (table.left.lower_bound(sym+"\xff"));
00046     if (i1 == i2)
00047         throw SyntaxErrorException("parameter syntax error: invalid enum value: ")
00048             << tokens.begin()[0].value();
00049     long v (i1->second);
00050     if (boost::algorithm::to_lower_copy(i1->first) == sym)
00051         return v;
00052     ++i1;
00053     if (i1 != i2)
00054         throw SyntaxErrorException("parameter syntax error: ambiguous enum value: ")
00055             << tokens.begin()[0].value();
00056     return v;
00057 }
00058 
00059 prefix_ std::string senf::console::detail::formatEnum(EnumTable const & table, long value)
00060 {
00061     EnumTable::right_map::const_iterator i (table.right.find(value));
00062     SENF_ASSERT( i != table.right.end(), "Invalid enum value" );
00063     return i->second;
00064 }
00065 
00066 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00067 #undef prefix_
00068 //#include "Traits.mpp"
00069 
00070 
00071 // Local Variables:
00072 // mode: c++
00073 // fill-column: 100
00074 // comment-column: 40
00075 // c-file-style: "senf"
00076 // indent-tabs-mode: nil
00077 // ispell-local-dictionary: "american"
00078 // compile-command: "scons -u test"
00079 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research