blob: e1aad363659165b618c2db71d9bad43517b584df [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001/*
2 * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef BTREE_HPP
18#define BTREE_HPP
19
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040020#include <vector>
thata1ad19f2014-11-08 01:18:44 +010021#include <string>
that9e0593e2014-10-08 00:01:24 +020022#include <map>
23#include "MtpTypes.h"
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040024
that9e0593e2014-10-08 00:01:24 +020025// A directory entry
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040026class Node {
that9e0593e2014-10-08 00:01:24 +020027 MtpObjectHandle handle;
28 MtpObjectHandle parent;
29 std::string name; // name only without path
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040030
31public:
32 Node();
that9e0593e2014-10-08 00:01:24 +020033 Node(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name);
34 virtual ~Node() {}
35
36 virtual bool isDir() const { return false; }
37
38 void rename(const std::string& newName);
39 MtpObjectHandle Mtpid() const;
40 MtpObjectHandle getMtpParentId() const;
41 const std::string& getName() const;
42
43 void addProperty(MtpPropertyCode property, uint64_t valueInt, std::string valueStr, MtpDataType dataType);
44 void updateProperty(MtpPropertyCode property, uint64_t valueInt, std::string valueStr, MtpDataType dataType);
45 void addProperties(const std::string& path, int storageID);
46 uint64_t getIntProperty(MtpPropertyCode property);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040047 struct mtpProperty {
that9e0593e2014-10-08 00:01:24 +020048 MtpPropertyCode property;
49 MtpDataType dataType;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040050 uint64_t valueInt;
51 std::string valueStr;
that9e0593e2014-10-08 00:01:24 +020052 mtpProperty() : property(0), dataType(0), valueInt(0) {}
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040053 };
54 std::vector<mtpProperty>& getMtpProps();
55 std::vector<mtpProperty> mtpProp;
that9e0593e2014-10-08 00:01:24 +020056 const mtpProperty& getProperty(MtpPropertyCode property);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040057};
58
that9e0593e2014-10-08 00:01:24 +020059// A directory
60class Tree : public Node {
61 std::map<MtpObjectHandle, Node*> entries;
62 bool alreadyRead;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040063public:
that9e0593e2014-10-08 00:01:24 +020064 Tree(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040065 ~Tree();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040066
that9e0593e2014-10-08 00:01:24 +020067 virtual bool isDir() const { return true; }
68
69 void addEntry(Node* node);
70 Node* findNode(MtpObjectHandle handle);
71 void getmtpids(MtpObjectHandleList* mtpids);
72 void deleteNode(MtpObjectHandle handle);
73 std::string getPath(Node* node);
74 int getMtpParentId() { return Node::getMtpParentId(); }
75 int getMtpParentId(Node* node);
76 Node* findEntryByName(std::string name);
77 int getCount();
78 bool wasAlreadyRead() const { return alreadyRead; }
79 void setAlreadyRead(bool b) { alreadyRead = b; }
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040080};
81
82#endif