diff options
author | jyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-20 01:27:34 +0000 |
---|---|---|
committer | jyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-20 01:27:34 +0000 |
commit | dc31f646fee5f9a5039fb6118b14fd66ba1464d4 (patch) | |
tree | e9575c5b3e92851300ed4db6dd502c8dbfd7678c /tools/json_schema_compiler | |
parent | a7f889754db1b3e8210cb938bab27ff26d5cc6d9 (diff) | |
download | chromium_src-dc31f646fee5f9a5039fb6118b14fd66ba1464d4.zip chromium_src-dc31f646fee5f9a5039fb6118b14fd66ba1464d4.tar.gz chromium_src-dc31f646fee5f9a5039fb6118b14fd66ba1464d4.tar.bz2 |
Represent BINARY properties using std::string instead of BinaryValue,
for easier use by C++.
Review URL: https://chromiumcodereview.appspot.com/10700194
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/cc_generator.py | 26 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 9 |
2 files changed, 20 insertions, 15 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py index d21e160..770ae48 100644 --- a/tools/json_schema_compiler/cc_generator.py +++ b/tools/json_schema_compiler/cc_generator.py @@ -355,7 +355,12 @@ class CCGenerator(object): elif prop.type_ == PropertyType.ENUM: return 'CreateEnumValue(%s).release()' % var elif prop.type_ == PropertyType.BINARY: - return '%s->DeepCopy()' % var + if prop.optional: + vardot = var + '->' + else: + vardot = var + '.' + return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % + (vardot, vardot)) elif self._IsArrayOrArrayRef(prop): return '%s.release()' % self._util_cc_helper.CreateValueFromArray( self._cpp_type_generator.GetReferencedProperty(prop), var, @@ -542,15 +547,20 @@ class CCGenerator(object): c.Append('%(dst)s->%(name)s = enum_temp;') c.Eblock('}') elif prop.type_ == PropertyType.BINARY: - # This is the same if the property is optional or not. We need a pointer - # to the base::BinaryValue to be able to populate it, so a scoped_ptr is - # used whether it is optional or required. (c.Append('if (!%(value_var)s->IsType(%(value_type)s))') .Append(' return %(failure_value)s;') - .Append('%(dst)s->%(name)s.reset(') - .Append(' static_cast<base::BinaryValue*>(%(value_var)s)' - '->DeepCopy());') - ) + .Append('base::BinaryValue* binary_value =') + .Append(' static_cast<base::BinaryValue*>(%(value_var)s);') + ) + if prop.optional: + (c.Append('%(dst)s->%(name)s.reset(') + .Append(' new std::string(binary_value->GetBuffer(),') + .Append(' binary_value->GetSize()));') + ) + else: + (c.Append('%(dst)s->%(name)s.assign(binary_value->GetBuffer(),') + .Append(' binary_value->GetSize());') + ) else: raise NotImplementedError(prop.type_) c.Eblock('}') diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 5b54bae..f398c75 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -127,7 +127,6 @@ class CppTypeGenerator(object): optional. """ cpp_type = None - force_wrapping = False if prop.type_ == PropertyType.REF: dependency_namespace = self._ResolveTypeNamespace(prop.ref_type) if not dependency_namespace: @@ -165,17 +164,13 @@ class CppTypeGenerator(object): cpp_type = cpp_type % self.GetType( prop.item_type, pad_for_generics=True) elif prop.type_ == PropertyType.BINARY: - # Since base::BinaryValue's are immutable, we wrap them in a scoped_ptr to - # allow them to be modified after the fact. - force_wrapping = True - cpp_type = 'base::BinaryValue' + cpp_type = 'std::string' else: raise NotImplementedError(prop.type_) # Enums aren't wrapped because C++ won't allow it. Optional enums have a # NONE value generated instead. - if force_wrapping or (wrap_optional and prop.optional and prop.type_ != - PropertyType.ENUM): + if wrap_optional and prop.optional and prop.type_ != PropertyType.ENUM: cpp_type = 'scoped_ptr<%s> ' % cpp_type if pad_for_generics: return cpp_type |