summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/extensions/dict_field.h
blob: d1370258af10986dc010c534d1dd10e26f747fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_
#define PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_

#include <string>

#include "ppapi/cpp/extensions/optional.h"

namespace pp {

class Var;

namespace ext {

template <class T>
class DictField {
 public:
  explicit DictField(const std::string& in_key) : key(in_key), value() {
  }

  ~DictField() {
  }

  // Adds this field to the dictionary var.
  bool AddTo(Var* /* var */) const {
    // TODO(yzshen): change Var to DictionaryVar and add support.
    return true;
  }

  bool Populate(const Var& /* var */) {
    // TODO(yzshen): change Var to DictionaryVar and add support.
    return true;
  }

  const std::string key;
  T value;
};

template <class T>
class OptionalDictField {
 public:
  explicit OptionalDictField(const std::string& in_key) : key(in_key) {
  }

  ~OptionalDictField() {
  }

  // Adds this field to the dictionary var, if |value| has been set.
  bool MayAddTo(Var* /* var */) const {
    // TODO(yzshen): change Var to DictionaryVar and add support
    return true;
  }

  bool Populate(const Var& /* var */) {
    // TODO(yzshen): change Var to DictionaryVar and add support.
    return true;
  }

  const std::string key;
  Optional<T> value;
};

}  // namespace ext
}  // namespace pp

#endif  // PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_