bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1 | /* |
| 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 bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 20 | #include <vector> |
that | a1ad19f | 2014-11-08 01:18:44 +0100 | [diff] [blame] | 21 | #include <string> |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 22 | #include <map> |
| 23 | #include "MtpTypes.h" |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 24 | |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 25 | // A directory entry |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 26 | class Node { |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 27 | MtpObjectHandle handle; |
| 28 | MtpObjectHandle parent; |
| 29 | std::string name; // name only without path |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 30 | |
| 31 | public: |
| 32 | Node(); |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 33 | 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 bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 47 | struct mtpProperty { |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 48 | MtpPropertyCode property; |
| 49 | MtpDataType dataType; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 50 | uint64_t valueInt; |
| 51 | std::string valueStr; |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 52 | mtpProperty() : property(0), dataType(0), valueInt(0) {} |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 53 | }; |
| 54 | std::vector<mtpProperty>& getMtpProps(); |
| 55 | std::vector<mtpProperty> mtpProp; |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 56 | const mtpProperty& getProperty(MtpPropertyCode property); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 59 | // A directory |
| 60 | class Tree : public Node { |
| 61 | std::map<MtpObjectHandle, Node*> entries; |
| 62 | bool alreadyRead; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 63 | public: |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 64 | Tree(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 65 | ~Tree(); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 66 | |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 67 | 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 bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | #endif |