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