Listable, json tweaks

This commit is contained in:
Henrik Rydgard
2012-06-03 17:24:33 +02:00
parent e7bf0303e2
commit a1f8b7e6e1
3 changed files with 19 additions and 4 deletions

View File

@@ -33,7 +33,7 @@ struct Clip {
// If current_clip == 0, the channel is free.
enum PlaybackState {
enum ClipPlaybackState {
PB_STOPPED = 0,
PB_PLAYING = 1,
};
@@ -42,7 +42,7 @@ enum PlaybackState {
struct Channel {
const Clip *current_clip;
// Playback state
PlaybackState state;
ClipPlaybackState state;
int pos;
PlayParams params;
// Effect state

View File

@@ -9,19 +9,30 @@ public:
virtual ~Listable() {}
virtual const char *getItem(size_t i) const = 0;
virtual size_t numItems() const = 0;
// Returns -1 for not found.
// Child classes are meant to specialize this if they have a faster way
// than brute force search.
virtual int getIndex(const char *text) {
for (size_t i = 0; i < numItems(); i++) {
if (!strcmp(getItem(i), text))
return i;
}
return -1;
}
};
class ArrayListable : public Listable
{
public:
ArrayListable(const char **arr, size_t count) : arr_(arr), count_(count) {}
ArrayListable(const char * const*arr, size_t count) : arr_(arr), count_(count) {}
virtual ~ArrayListable() {}
virtual const char *getItem(size_t i) const { return arr_[i]; }
virtual size_t numItems() const { return count_; }
private:
const char **arr_;
const char *const*arr_;
size_t count_;
};

View File

@@ -57,6 +57,10 @@ struct json_value
bool getBool(const char *child_name) const;
bool getBool(const char *child_name, bool default_value) const;
bool hasChild(const char *child_name, json_type child_type) const {
return get(child_name, child_type) != 0;
}
private:
DISALLOW_COPY_AND_ASSIGN(json_value);
};