Pepper_56_C++_interfaces
Pepper_56_C++_interfaces
 All Classes Namespaces Files Functions Typedefs Enumerations Macros Groups
directory_entry.h
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_CPP_DIRECTORY_ENTRY_H_
6 #define PPAPI_CPP_DIRECTORY_ENTRY_H_
7 
8 #include <vector>
9 
10 #include "ppapi/c/pp_array_output.h"
11 #include "ppapi/c/pp_directory_entry.h"
12 #include "ppapi/cpp/array_output.h"
13 #include "ppapi/cpp/file_ref.h"
15 #include "ppapi/cpp/pass_ref.h"
16 
19 
20 namespace pp {
21 
25  public:
29 
35  DirectoryEntry(PassRef, const PP_DirectoryEntry& data);
36 
42  DirectoryEntry(const DirectoryEntry& other);
43 
47 
57 
62  bool is_null() const { return !data_.file_ref; }
63 
68  FileRef file_ref() const { return FileRef(data_.file_ref); }
69 
74  PP_FileType file_type() const { return data_.file_type; }
75 
76  private:
77  PP_DirectoryEntry data_;
78 };
79 
80 namespace internal {
81 
83  : public ArrayOutputAdapter<PP_DirectoryEntry> {
84  public:
87 
88  // Returns the final array of resource objects, converting the
89  // PP_DirectoryEntry written by the browser to pp::DirectoryEntry
90  // objects.
91  //
92  // This function should only be called once or we would end up converting
93  // the array more than once, which would mess up the refcounting.
94  std::vector<DirectoryEntry>& output();
95 
96  private:
97  // The browser will write the PP_DirectoryEntrys into this array.
98  std::vector<PP_DirectoryEntry> temp_storage_;
99 
100  // When asked for the output, the PP_DirectoryEntrys above will be
101  // converted to the pp::DirectoryEntrys in this array for passing to the
102  // calling code.
103  std::vector<DirectoryEntry> output_storage_;
104 };
105 
106 // A specialization of CallbackOutputTraits to provide the callback system the
107 // information on how to handle vectors of pp::DirectoryEntry. This converts
108 // PP_DirectoryEntry to pp::DirectoryEntry when passing to the plugin.
109 template <>
110 struct CallbackOutputTraits< std::vector<DirectoryEntry> > {
111  typedef PP_ArrayOutput APIArgType;
113 
114  static inline APIArgType StorageToAPIArg(StorageType& t) {
115  return t.pp_array_output();
116  }
117 
118  static inline std::vector<DirectoryEntry>& StorageToPluginArg(
119  StorageType& t) {
120  return t.output();
121  }
122 
123  static inline void Initialize(StorageType* /* t */) {}
124 };
125 
126 } // namespace internal
127 } // namespace pp
128 
129 #endif // PPAPI_CPP_DIRECTORY_ENTRY_H_
DirectoryEntry & operator=(const DirectoryEntry &other)
Definition: directory_entry.h:82
Definition: file_ref.h:27
~DirectoryEntry()
Definition: output_traits.h:132
DirectoryEntry()
Definition: array_output.h:87
Definition: directory_entry.h:24
PP_FileType file_type() const
Definition: directory_entry.h:74
PassRef
Definition: pass_ref.h:17
FileRef file_ref() const
Definition: directory_entry.h:68
bool is_null() const
Definition: directory_entry.h:62