Devices: Make get methods of Device const

adds const qualifiers to the devices class getter methods.

Resolves the TODO: Make Get methods of device const in
documentation/Todo.txt

Changes:
- Added const qualifiers to getter methods in Device.h and Device.cpp
- replaced operator[] with find() in Device.h and Device.cpp to prevent
map modification in const
- Removed the corresponding Todo entry in documentation/Todo.txt

Change-Id: I78d5ea31b2d7539bcefda7b3e57a484d16103c25
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10666
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Leo Rouleau
2026-04-06 07:44:09 +00:00
committed by Adrien Destugues
parent 734225977f
commit 84dc21e19e
3 changed files with 35 additions and 20 deletions
+22 -10
View File
@@ -74,30 +74,42 @@ Device::~Device()
BString
Device::GetName()
Device::GetName() const
{
return fAttributeMap[B_TRANSLATE("Device name")];
AttributeMapIterator it = fAttributeMap.find(B_TRANSLATE("Device name"));
if (it != fAttributeMap.end())
return it->second;
return BString("unkown");
}
BString
Device::GetManufacturer()
Device::GetManufacturer() const
{
return fAttributeMap[B_TRANSLATE("Manufacturer")];
AttributeMapIterator it = fAttributeMap.find(B_TRANSLATE("Manufacturer"));
if (it != fAttributeMap.end())
return it->second;
return BString("Unknown");
}
BString
Device::GetDriverUsed()
Device::GetDriverUsed() const
{
return fAttributeMap[B_TRANSLATE("Driver used")];
AttributeMapIterator it = fAttributeMap.find(B_TRANSLATE("Driver used"));
if (it != fAttributeMap.end())
return it->second;
return BString("Unknown");
}
BString
Device::GetDevPathsPublished()
Device::GetDevPathsPublished() const
{
return fAttributeMap[B_TRANSLATE("Device paths")];
AttributeMapIterator it = fAttributeMap.find(B_TRANSLATE("Device paths"));
if (it != fAttributeMap.end())
return it->second;
return BString("Unknown");
}
@@ -112,7 +124,7 @@ Device::SetAttribute(const BString& name, const BString& value)
Attributes
Device::GetAllAttributes()
Device::GetAllAttributes() const
{
Attributes attributes;
AttributeMapIterator iter;
@@ -124,7 +136,7 @@ Device::GetAllAttributes()
BString
Device::GetAllStrings()
Device::GetAllStrings() const
{
BString str;
AttributeMapIterator iter;
+13 -9
View File
@@ -83,10 +83,10 @@ public:
const BString& devPathsPublished = "unknown");
virtual ~Device();
virtual BString GetName();
virtual BString GetManufacturer();
virtual BString GetDriverUsed();
virtual BString GetDevPathsPublished();
virtual BString GetName() const;
virtual BString GetManufacturer() const;
virtual BString GetDriverUsed() const;
virtual BString GetDevPathsPublished() const;
virtual Category GetCategory() const
{ return fCategory; }
virtual Device* GetPhysicalParent() const
@@ -94,12 +94,16 @@ public:
virtual BusType GetBusType() const
{ return fBusType; }
virtual Attributes GetAllAttributes();
virtual BString GetAllStrings();
virtual Attributes GetAllAttributes() const;
virtual BString GetAllStrings() const;
virtual Attribute GetAttribute(const BString& name)
{ return Attribute(name.String(),
fAttributeMap[name]); }
virtual Attribute GetAttribute(const BString& name) const
{
AttributeMapIterator it = fAttributeMap.find(name);
if (it != fAttributeMap.end())
return Attribute(name.String(), it->second);
return Attribute(name.String(), "");
}
virtual void SetAttribute(const BString& name,
const BString& value);
-1
View File
@@ -1,6 +1,5 @@
TODO:
* There still is a memory leak somewhere, hunt it down
* Make Get methods of Device const
* Fix view color?
* Fix forwarding of messages to view
* Bottom scrollbar strangeness