blob: b284e4f4b7367b7324d520d61f325a7f105d64cc [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>
that9e0593e2014-10-08 00:01:24 +020021#include <map>
22#include "MtpTypes.h"
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040023
that9e0593e2014-10-08 00:01:24 +020024// A directory entry
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040025class Node {
that9e0593e2014-10-08 00:01:24 +020026 MtpObjectHandle handle;
27 MtpObjectHandle parent;
28 std::string name; // name only without path
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040029
30public:
31 Node();
that9e0593e2014-10-08 00:01:24 +020032 Node(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name);
33 virtual ~Node() {}
34
35 virtual bool isDir() const { return false; }
36
37 void rename(const std::string& newName);
38 MtpObjectHandle Mtpid() const;
39 MtpObjectHandle getMtpParentId() const;
40 const std::string& getName() const;
41
42 void addProperty(MtpPropertyCode property, uint64_t valueInt, std::string valueStr, MtpDataType dataType);
43 void updateProperty(MtpPropertyCode property, uint64_t valueInt, std::string valueStr, MtpDataType dataType);
44 void addProperties(const std::string& path, int storageID);
45 uint64_t getIntProperty(MtpPropertyCode property);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040046 struct mtpProperty {
that9e0593e2014-10-08 00:01:24 +020047 MtpPropertyCode property;
48 MtpDataType dataType;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040049 uint64_t valueInt;
50 std::string valueStr;
that9e0593e2014-10-08 00:01:24 +020051 mtpProperty() : property(0), dataType(0), valueInt(0) {}
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040052 };
53 std::vector<mtpProperty>& getMtpProps();
54 std::vector<mtpProperty> mtpProp;
that9e0593e2014-10-08 00:01:24 +020055 const mtpProperty& getProperty(MtpPropertyCode property);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040056};
57
that9e0593e2014-10-08 00:01:24 +020058// A directory
59class Tree : public Node {
60 std::map<MtpObjectHandle, Node*> entries;
61 bool alreadyRead;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040062public:
that9e0593e2014-10-08 00:01:24 +020063 Tree(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040064 ~Tree();
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040065
that9e0593e2014-10-08 00:01:24 +020066 virtual bool isDir() const { return true; }
67
68 void addEntry(Node* node);
69 Node* findNode(MtpObjectHandle handle);
70 void getmtpids(MtpObjectHandleList* mtpids);
71 void deleteNode(MtpObjectHandle handle);
72 std::string getPath(Node* node);
73 int getMtpParentId() { return Node::getMtpParentId(); }
74 int getMtpParentId(Node* node);
75 Node* findEntryByName(std::string name);
76 int getCount();
77 bool wasAlreadyRead() const { return alreadyRead; }
78 void setAlreadyRead(bool b) { alreadyRead = b; }
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040079};
80
81#endif