Blame src/cppvalue.h

Packit 1c1d7e
/******************************************************************************
Packit 1c1d7e
 *
Packit 1c1d7e
 * 
Packit 1c1d7e
 *
Packit 1c1d7e
 *
Packit 1c1d7e
 * Copyright (C) 1997-2015 by Dimitri van Heesch.
Packit 1c1d7e
 *
Packit 1c1d7e
 * Permission to use, copy, modify, and distribute this software and its
Packit 1c1d7e
 * documentation under the terms of the GNU General Public License is hereby 
Packit 1c1d7e
 * granted. No representations are made about the suitability of this software 
Packit 1c1d7e
 * for any purpose. It is provided "as is" without express or implied warranty.
Packit 1c1d7e
 * See the GNU General Public License for more details.
Packit 1c1d7e
 *
Packit 1c1d7e
 * Documents produced by Doxygen are derivative works derived from the
Packit 1c1d7e
 * input used in their production; they are not affected by this license.
Packit 1c1d7e
 *
Packit 1c1d7e
 */
Packit 1c1d7e
Packit 1c1d7e
#ifndef _CPPVALUE_H
Packit 1c1d7e
#define _CPPVALUE_H
Packit 1c1d7e
Packit 1c1d7e
#include <stdio.h>
Packit 1c1d7e
#include <qglobal.h> 
Packit 1c1d7e
Packit 1c1d7e
/** A class representing a C-preprocessor value. */
Packit 1c1d7e
class CPPValue
Packit 1c1d7e
{
Packit 1c1d7e
  public:
Packit 1c1d7e
    enum Type { Int, Float };
Packit 1c1d7e
  
Packit 1c1d7e
    CPPValue(long val=0) : type(Int) { v.l = val; }
Packit 1c1d7e
    CPPValue(double val) : type(Float) { v.d = val; }
Packit 1c1d7e
Packit 1c1d7e
    operator double () const { return type==Int ? (double)v.l : v.d; }
Packit 1c1d7e
    operator long ()   const { return type==Int ? v.l : (long)v.d;   }
Packit 1c1d7e
Packit 1c1d7e
    bool isInt() const { return type == Int; }
Packit 1c1d7e
     
Packit 1c1d7e
    void print() const
Packit 1c1d7e
    {
Packit 1c1d7e
      if (type==Int) 
Packit 1c1d7e
        printf("(%ld)\n",v.l);
Packit 1c1d7e
      else
Packit 1c1d7e
        printf("(%f)\n",v.d);
Packit 1c1d7e
    }
Packit 1c1d7e
Packit 1c1d7e
  private:
Packit 1c1d7e
    Type type;
Packit 1c1d7e
    union {
Packit 1c1d7e
      double d;
Packit 1c1d7e
      long l;
Packit 1c1d7e
    } v;
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
extern CPPValue parseOctal();
Packit 1c1d7e
extern CPPValue parseDecimal();
Packit 1c1d7e
extern CPPValue parseHexadecimal();
Packit 1c1d7e
extern CPPValue parseCharacter();
Packit 1c1d7e
extern CPPValue parseFloat();
Packit 1c1d7e
Packit 1c1d7e
#endif