| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PPAPI_SHARED_IMPL_VAR_H_ | 5 #ifndef PPAPI_SHARED_IMPL_VAR_H_ |
| 6 #define PPAPI_SHARED_IMPL_VAR_H_ | 6 #define PPAPI_SHARED_IMPL_VAR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // StringVar ------------------------------------------------------------------- | 79 // StringVar ------------------------------------------------------------------- |
| 80 | 80 |
| 81 // Represents a string-based Var. | 81 // Represents a string-based Var. |
| 82 // | 82 // |
| 83 // Returning a given string as a PP_Var: | 83 // Returning a given string as a PP_Var: |
| 84 // return StringVar::StringToPPVar(module, my_string); | 84 // return StringVar::StringToPPVar(module, my_string); |
| 85 // | 85 // |
| 86 // Converting a PP_Var to a string: | 86 // Converting a PP_Var to a string: |
| 87 // scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); | 87 // StringVar* string = StringVar::FromPPVar(var); |
| 88 // if (!string) | 88 // if (!string) |
| 89 // return false; // Not a string or an invalid var. | 89 // return false; // Not a string or an invalid var. |
| 90 // DoSomethingWithTheString(string->value()); | 90 // DoSomethingWithTheString(string->value()); |
| 91 class StringVar : public Var { | 91 class StringVar : public Var { |
| 92 public: | 92 public: |
| 93 StringVar(PP_Module module, const char* str, uint32 len); | 93 StringVar(PP_Module module, const char* str, uint32 len); |
| 94 virtual ~StringVar(); | 94 virtual ~StringVar(); |
| 95 | 95 |
| 96 const std::string& value() const { return value_; } | 96 const std::string& value() const { return value_; } |
| 97 | 97 |
| 98 // Var override. | 98 // Var override. |
| 99 virtual StringVar* AsStringVar() OVERRIDE; | 99 virtual StringVar* AsStringVar() OVERRIDE; |
| 100 virtual PP_Var GetPPVar() OVERRIDE; | 100 virtual PP_Var GetPPVar() OVERRIDE; |
| 101 virtual PP_VarType GetType() const OVERRIDE; | 101 virtual PP_VarType GetType() const OVERRIDE; |
| 102 | 102 |
| 103 // Helper function to create a PP_Var of type string that contains a copy of | 103 // Helper function to create a PP_Var of type string that contains a copy of |
| 104 // the given string. The input data must be valid UTF-8 encoded text, if it | 104 // the given string. The input data must be valid UTF-8 encoded text, if it |
| 105 // is not valid UTF-8, a NULL var will be returned. | 105 // is not valid UTF-8, a NULL var will be returned. |
| 106 // | 106 // |
| 107 // The return value will have a reference count of 1. Internally, this will | 107 // The return value will have a reference count of 1. Internally, this will |
| 108 // create a StringVar, associate it with a module, and return the reference | 108 // create a StringVar, associate it with a module, and return the reference |
| 109 // to it in the var. | 109 // to it in the var. |
| 110 static PP_Var StringToPPVar(PP_Module module, const std::string& str); | 110 static PP_Var StringToPPVar(PP_Module module, const std::string& str); |
| 111 static PP_Var StringToPPVar(PP_Module module, const char* str, uint32 len); | 111 static PP_Var StringToPPVar(PP_Module module, const char* str, uint32 len); |
| 112 | 112 |
| 113 // Helper function that converts a PP_Var to a string. This will return NULL | 113 // Helper function that converts a PP_Var to a string. This will return NULL |
| 114 // if the PP_Var is not of string type or the string is invalid. | 114 // if the PP_Var is not of string type or the string is invalid. |
| 115 static scoped_refptr<StringVar> FromPPVar(PP_Var var); | 115 static StringVar* FromPPVar(PP_Var var); |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 std::string value_; | 118 std::string value_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(StringVar); | 120 DISALLOW_COPY_AND_ASSIGN(StringVar); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 } // namespace ppapi | 123 } // namespace ppapi |
| 124 | 124 |
| 125 #endif // PPAPI_SHARED_IMPL_VAR_H_ | 125 #endif // PPAPI_SHARED_IMPL_VAR_H_ |
| OLD | NEW |