1 // Copyright 2013 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.
5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_PMP_COLUMN_READER_H_
6 #define CHROME_UTILITY_MEDIA_GALLERIES_PMP_COLUMN_READER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/platform_file.h"
14 #include "chrome/common/media_galleries/pmp_constants.h"
22 // Reads a single PMP column from a file.
23 class PmpColumnReader
{
26 virtual ~PmpColumnReader();
28 // Returns true if read successfully.
29 // |rows_read| is undefined if returns false.
30 bool ReadFile(base::PlatformFile file
, const PmpFieldType expected_type
);
32 // These functions read the value of that |row| into |result|.
33 // Functions return false if the column is of the wrong type or the row
34 // is out of range. May only be called after successful ReadColumn.
35 bool ReadString(const uint32 row
, std::string
* result
) const;
36 bool ReadUInt32(const uint32 row
, uint32
* result
) const;
37 bool ReadDouble64(const uint32 row
, double* result
) const;
38 bool ReadUInt8(const uint32 row
, uint8
* result
) const;
39 bool ReadUInt64(const uint32 row
, uint64
* result
) const;
41 // May only be called after successful ReadColumn.
42 uint32
rows_read() const;
45 bool ParseData(const PmpFieldType expected_type
);
46 // Returns the number of bytes parsed in the body, or, -1 on failure.
50 scoped_ptr
<uint8
[]> data_
;
54 PmpFieldType field_type_
;
57 // Index of string start locations if fields are strings. Empty otherwise.
58 std::vector
<const char*> strings_
;
60 DISALLOW_COPY_AND_ASSIGN(PmpColumnReader
);
65 #endif // CHROME_UTILITY_MEDIA_GALLERIES_PMP_COLUMN_READER_H_