Blame src/cppvalue.h

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