Retro68/Rez/ResourceDefinitions.h

117 lines
2.3 KiB
C
Raw Normal View History

2014-10-06 15:03:25 +00:00
#ifndef RESOURCEDEFINITIONS_H
#define RESOURCEDEFINITIONS_H
#include <iosfwd>
#include <memory>
#include <map>
#include "Expression.h"
2014-10-06 15:03:25 +00:00
class ResType
{
int x;
public:
ResType() : x(0) {}
ResType(int x) : x(x) {}
operator int() const { return x; }
bool operator<(ResType y) const { return x < y.x; }
2014-10-06 15:03:25 +00:00
};
std::ostream& operator<<(std::ostream& out, ResType t);
class TypeSpec
{
ResType type;
int id;
public:
static const int noID = 65536;
TypeSpec() : id(noID) {}
TypeSpec(ResType type) : type(type), id(noID) {}
TypeSpec(ResType type, int id) : type(type), id(id) {}
ResType getType() const { return type; }
int getID() const { return id; }
bool hasID() const { return id != noID; }
bool operator<(TypeSpec y) const
{
if(type < y.type)
return true;
else if(y.type < type)
return false;
else
return id < y.id;
}
2014-10-06 15:03:25 +00:00
};
std::ostream& operator<<(std::ostream& out, TypeSpec ts);
2014-10-06 15:03:25 +00:00
class ResourceCompiler;
2014-10-06 15:03:25 +00:00
class Field
{
public:
virtual bool needsValue() { return true; }
virtual void compile(ExprPtr expr, ResourceCompiler *compiler, bool prePass) = 0;
2014-10-06 15:03:25 +00:00
};
typedef std::shared_ptr<Field> FieldPtr;
class SimpleField : public Field
{
public:
enum class Type
{
boolean, byte, integer, longint, rect, point, char_,
pstring, wstring, string, bitstring
};
enum class Attrs
{
none = 0, hex = 1, key = 2, unsigned_ = 4, literal = 8
};
Type type;
Attrs attrs = Attrs::none;
ExprPtr arrayCount;
ExprPtr value;
std::map<std::string, ExprPtr> namedValues;
void addNamedValue(std::string n) {}
void addNamedValue(std::string n, ExprPtr val) {}
virtual bool needsValue();
virtual void compile(ExprPtr expr, ResourceCompiler *compiler, bool prePass);
2014-10-06 15:03:25 +00:00
};
typedef std::shared_ptr<SimpleField> SimpleFieldPtr;
inline SimpleField::Attrs operator|(SimpleField::Attrs a, SimpleField::Attrs b)
{
return SimpleField::Attrs( int(a) | int(b) );
}
class FieldList : public Field
2014-10-06 15:03:25 +00:00
{
protected:
std::vector<FieldPtr> fields;
2014-10-06 15:03:25 +00:00
public:
virtual ~FieldList();
void addField(FieldPtr field);
void addLabel(std::string name);
virtual void compile(ExprPtr expr, ResourceCompiler *compiler, bool prePass);
};
typedef std::shared_ptr<FieldList> FieldListPtr;
class TypeDefinition : public FieldList
{
2014-10-06 15:03:25 +00:00
};
typedef std::shared_ptr<TypeDefinition> TypeDefinitionPtr;
2014-10-06 15:03:25 +00:00
#endif // RESOURCEDEFINITIONS_H