tool/DataTypeHandler.h
changeset 1835 20748e9d2238
child 1868 489ea0becd74
equal deleted inserted replaced
1834:67fc217d7341 1835:20748e9d2238
       
     1 /*****************************************************************************
       
     2  *
       
     3  *  $Id$
       
     4  *
       
     5  *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
       
     6  *
       
     7  *  This file is part of the IgH EtherCAT Master.
       
     8  *
       
     9  *  The IgH EtherCAT Master is free software; you can redistribute it and/or
       
    10  *  modify it under the terms of the GNU General Public License version 2, as
       
    11  *  published by the Free Software Foundation.
       
    12  *
       
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
       
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       
    16  *  Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License along
       
    19  *  with the IgH EtherCAT Master; if not, write to the Free Software
       
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    21  *
       
    22  *  ---
       
    23  *
       
    24  *  The license mentioned above concerns the source code only. Using the
       
    25  *  EtherCAT technology and brand is only permitted in compliance with the
       
    26  *  industrial property and similar rights of Beckhoff Automation GmbH.
       
    27  *
       
    28  ****************************************************************************/
       
    29 
       
    30 #ifndef __DATATYPEHANDLER_H__
       
    31 #define __DATATYPEHANDLER_H__
       
    32 
       
    33 /****************************************************************************/
       
    34 
       
    35 #include <stdint.h>
       
    36 #include <string>
       
    37 #include <stdexcept>
       
    38 #include <ostream>
       
    39 
       
    40 /****************************************************************************/
       
    41 
       
    42 class DataTypeHandler
       
    43 {
       
    44     public:
       
    45         DataTypeHandler();
       
    46 
       
    47     protected:
       
    48         struct DataType {
       
    49             const char *name;
       
    50             uint16_t code;
       
    51             size_t byteSize;
       
    52         };
       
    53 
       
    54         static const DataType *findDataType(const std::string &);
       
    55         static const DataType *findDataType(uint16_t);
       
    56         static size_t interpretAsType(const DataType *, const std::string &,
       
    57                 void *, size_t);
       
    58 
       
    59         class SizeException:
       
    60             public std::runtime_error
       
    61         {
       
    62             public:
       
    63                 SizeException(const std::string &msg):
       
    64                     runtime_error(msg) {}
       
    65         };
       
    66 
       
    67         static void outputData(std::ostream &, const DataType *,
       
    68                 void *, size_t);
       
    69         static void printRawData(ostream &, const uint8_t *, size_t);
       
    70 
       
    71     private:
       
    72         static const DataType dataTypes[];
       
    73 };
       
    74 
       
    75 /****************************************************************************/
       
    76 
       
    77 #endif