2009-07-22 14:15:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Günther Brammer <gbrammer@gmx.de>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
*/
|
|
|
|
|
2009-05-19 22:12:11 +00:00
|
|
|
/* Property lists */
|
|
|
|
|
|
|
|
#ifndef C4PROPLIST_H
|
|
|
|
#define C4PROPLIST_H
|
|
|
|
|
|
|
|
#include "C4Value.h"
|
|
|
|
#include "C4StringTable.h"
|
|
|
|
|
2009-10-25 23:09:34 +00:00
|
|
|
class C4Def;
|
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
class C4Property
|
|
|
|
{
|
|
|
|
public:
|
2009-07-26 20:31:45 +00:00
|
|
|
C4Property() : Key(0) {}
|
|
|
|
C4Property(C4String *Key, const C4Value &Value) : Key(Key), Value(Value)
|
2010-12-06 15:24:41 +00:00
|
|
|
{ assert(Key); Key->IncRef(); /*assert(Strings.Set.Has(Key));*/ }
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Property(const C4Property &o) : Key(o.Key), Value(o.Value) { if (Key) Key->IncRef(); }
|
2009-07-26 20:31:45 +00:00
|
|
|
C4Property & operator = (const C4Property &o)
|
2010-03-28 17:58:21 +00:00
|
|
|
{ assert(o.Key); o.Key->IncRef(); if (Key) Key->DecRef(); Key = o.Key; Value = o.Value; return *this; }
|
|
|
|
~C4Property() { if (Key) Key->DecRef(); }
|
2010-03-21 23:40:03 +00:00
|
|
|
void CompileFunc(StdCompiler *pComp);
|
2009-05-19 22:12:11 +00:00
|
|
|
C4String * Key;
|
|
|
|
C4Value Value;
|
2010-03-21 23:40:03 +00:00
|
|
|
operator const void * () const { return Key; }
|
2010-12-06 15:19:15 +00:00
|
|
|
C4Property & operator = (void * p)
|
|
|
|
{ assert(!p); if (Key) Key->DecRef(); Key = 0; Value.Set0(); return *this; }
|
2009-05-19 22:12:11 +00:00
|
|
|
};
|
2010-03-21 23:40:03 +00:00
|
|
|
class C4PropListNumbered;
|
2010-03-28 17:58:21 +00:00
|
|
|
class C4PropList
|
|
|
|
{
|
|
|
|
public:
|
2009-05-19 22:12:11 +00:00
|
|
|
void AddRef(C4Value *pRef);
|
|
|
|
void DelRef(const C4Value *pRef, C4Value * pNextRef);
|
2010-09-22 01:33:57 +00:00
|
|
|
void Clear() { constant = false; Properties.Clear(); prototype = 0; }
|
2009-04-03 19:06:29 +00:00
|
|
|
const char *GetName();
|
|
|
|
virtual void SetName (const char *NewName = 0);
|
2009-05-19 22:12:11 +00:00
|
|
|
|
2010-09-10 21:01:30 +00:00
|
|
|
virtual C4Def const * GetDef() const;
|
2009-04-12 12:04:28 +00:00
|
|
|
virtual C4Def * GetDef();
|
2009-04-18 00:46:19 +00:00
|
|
|
virtual C4Object * GetObject();
|
2010-03-21 23:40:03 +00:00
|
|
|
virtual C4PropListNumbered * GetPropListNumbered();
|
2010-09-10 21:01:30 +00:00
|
|
|
C4PropList * GetPrototype() const { return prototype; }
|
2009-04-12 12:04:28 +00:00
|
|
|
|
2010-09-08 18:09:27 +00:00
|
|
|
// Whether this proplist should be saved as a reference to a C4Def
|
2010-09-10 21:01:30 +00:00
|
|
|
virtual bool IsDef() const { return false; }
|
2010-09-08 18:09:27 +00:00
|
|
|
|
2010-12-06 15:19:15 +00:00
|
|
|
bool GetPropertyByS(C4String *k, C4Value *pResult) const;
|
|
|
|
bool GetProperty(C4PropertyName k, C4Value *pResult) const
|
2010-12-06 15:24:41 +00:00
|
|
|
{ return GetPropertyByS(&Strings.P[k], pResult); }
|
2010-09-10 21:01:30 +00:00
|
|
|
C4String * GetPropertyStr(C4PropertyName k) const;
|
|
|
|
int32_t GetPropertyInt(C4PropertyName k) const;
|
2010-09-08 12:54:39 +00:00
|
|
|
// not allowed on frozen proplists
|
2010-12-06 15:19:15 +00:00
|
|
|
void SetPropertyByS(C4String * k, const C4Value & to);
|
|
|
|
void SetProperty(C4PropertyName k, const C4Value & to)
|
2010-12-06 15:24:41 +00:00
|
|
|
{ SetPropertyByS(&Strings.P[k], to); }
|
2009-04-03 19:06:29 +00:00
|
|
|
void ResetProperty(C4String * k);
|
|
|
|
|
2010-03-21 23:40:03 +00:00
|
|
|
static C4PropList * New(C4PropList * prototype = 0);
|
2010-09-08 12:54:39 +00:00
|
|
|
static C4PropList * NewAnon(C4PropList * prototype = 0);
|
|
|
|
|
|
|
|
// only freeze proplists which are not going to be modified
|
|
|
|
void Freeze() { constant = true; }
|
2010-09-10 21:01:30 +00:00
|
|
|
bool IsFrozen() const { return constant; }
|
2010-09-08 12:54:39 +00:00
|
|
|
|
2010-03-21 23:40:03 +00:00
|
|
|
virtual void DenumeratePointers();
|
2009-05-19 22:12:11 +00:00
|
|
|
virtual ~C4PropList();
|
2009-04-03 19:06:29 +00:00
|
|
|
|
2010-03-21 23:40:03 +00:00
|
|
|
// Every proplist has to be initialized by either Init or CompileFunc.
|
|
|
|
void CompileFunc(StdCompiler *pComp);
|
2009-05-19 22:12:11 +00:00
|
|
|
|
2010-09-10 21:01:30 +00:00
|
|
|
bool operator==(const C4PropList &b) const;
|
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
protected:
|
2010-03-21 23:40:03 +00:00
|
|
|
C4PropList(C4PropList * prototype = 0);
|
2010-10-29 22:05:36 +00:00
|
|
|
C4Value *FirstRef; // No-Save
|
2010-03-21 23:40:03 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
private:
|
2010-10-17 20:13:12 +00:00
|
|
|
C4Set<C4Property> Properties;
|
2010-12-06 18:04:32 +00:00
|
|
|
C4PropList * prototype;
|
2010-09-08 12:54:39 +00:00
|
|
|
bool constant; // if true, this proplist is not changeable
|
2010-03-21 23:40:03 +00:00
|
|
|
|
|
|
|
friend void CompileNewFunc<C4PropList>(C4PropList *&pStruct, StdCompiler *pComp);
|
2010-12-06 18:04:32 +00:00
|
|
|
public:
|
|
|
|
int32_t Status;
|
2009-05-19 22:12:11 +00:00
|
|
|
};
|
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
class C4PropListNumbered: public C4PropList
|
|
|
|
{
|
|
|
|
public:
|
2010-03-21 23:40:03 +00:00
|
|
|
int32_t Number;
|
|
|
|
C4PropListNumbered(C4PropList * prototype = 0);
|
|
|
|
~C4PropListNumbered();
|
|
|
|
void CompileFunc(StdCompiler *pComp);
|
|
|
|
virtual C4PropListNumbered * GetPropListNumbered();
|
|
|
|
void AcquireNumber();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-19 22:12:11 +00:00
|
|
|
#endif // C4PROPLIST_H
|