headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / settings / TeamFileManagerSettings.cpp
blobdae7c79f0f97155dc01467d874efab30fc5cb04a
1 /*
2 * Copyright 2013, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "TeamFileManagerSettings.h"
7 TeamFileManagerSettings::TeamFileManagerSettings()
9 fValues()
14 TeamFileManagerSettings::~TeamFileManagerSettings()
19 TeamFileManagerSettings&
20 TeamFileManagerSettings::operator=(const TeamFileManagerSettings& other)
22 fValues = other.fValues;
24 return *this;
28 const char*
29 TeamFileManagerSettings::ID() const
31 return "FileManager";
35 status_t
36 TeamFileManagerSettings::SetTo(const BMessage& archive)
38 try {
39 fValues = archive;
40 } catch (...) {
41 return B_NO_MEMORY;
44 return B_OK;
48 status_t
49 TeamFileManagerSettings::WriteTo(BMessage& archive) const
51 try {
52 archive = fValues;
53 } catch (...) {
54 return B_NO_MEMORY;
57 return B_OK;
61 int32
62 TeamFileManagerSettings::CountSourceMappings() const
64 type_code type;
65 int32 count = 0;
67 if (fValues.GetInfo("source:mapping", &type, &count) == B_OK)
68 return count;
70 return 0;
74 status_t
75 TeamFileManagerSettings::AddSourceMapping(const BString& sourcePath,
76 const BString& locatedPath)
78 BMessage mapping;
79 if (mapping.AddString("source:path", sourcePath) != B_OK
80 || mapping.AddString("source:locatedpath", locatedPath) != B_OK
81 || fValues.AddMessage("source:mapping", &mapping) != B_OK) {
82 return B_NO_MEMORY;
85 return B_OK;
89 status_t
90 TeamFileManagerSettings::RemoveSourceMappingAt(int32 index)
92 return fValues.RemoveData("source:mapping", index);
96 status_t
97 TeamFileManagerSettings::GetSourceMappingAt(int32 index, BString& sourcePath,
98 BString& locatedPath)
100 BMessage mapping;
101 status_t error = fValues.FindMessage("source:mapping", index, &mapping);
102 if (error != B_OK)
103 return error;
105 error = mapping.FindString("source:path", &sourcePath);
106 if (error != B_OK)
107 return error;
109 return mapping.FindString("source:locatedpath", &locatedPath);
113 TeamFileManagerSettings*
114 TeamFileManagerSettings::Clone() const
116 TeamFileManagerSettings* settings = new(std::nothrow)
117 TeamFileManagerSettings();
119 if (settings == NULL)
120 return NULL;
122 if (settings->SetTo(fValues) != B_OK) {
123 delete settings;
124 return NULL;
127 return settings;