skia2/include/utils/SkJSONObject.h
mike@reedtribe.org 41f1c46ddc add experimental class for json
git-svn-id: http://skia.googlecode.com/svn/trunk@2939 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-31 01:58:40 +00:00

61 lines
1.5 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkJSONObject_DEFINED
#define SkJSONObject_DEFINED
#include "SkTypes.h"
class SkString;
class SkJSONObject {
public:
SkJSONObject() : fHead(NULL), fTail(NULL) {}
~SkJSONObject();
enum Type {
kInvalid,
kObject,
kString,
kInt,
kFloat,
kBool,
};
void addString(const char name[], const char value[]);
void addInt(const char name[], int32_t value);
void addFloat(const char name[], float value);
void addBool(const char name[], bool value);
/**
* Add the value object to this object, taking over
* ownership of the value object.
*/
void addObject(const char name[], SkJSONObject* value);
Type find(const char name[], intptr_t* = NULL) const;
bool findString(const char name[], SkString* = NULL) const;
bool findInt(const char name[], int32_t* = NULL) const;
bool findFloat(const char name[], float* = NULL) const;
bool findBool(const char name[], bool* = NULL) const;
bool findObject(const char name[], SkJSONObject** = NULL) const;
void dump() const;
private:
struct Slot;
Slot* fHead;
Slot* fTail;
const Slot* findSlot(const char name[]) const;
const Slot* findSlotAndType(const char name[], Type) const;
Slot* addSlot(Slot*);
void dumpLevel(int level) const;
};
#endif