vfs: check userland buffers before reading them.
[haiku.git] / src / apps / debugger / user_interface / gui / value / TableCellEnumerationEditor.cpp
bloba164c1250f75f72c4253b352bf2e06d8ac3e4b3e
1 /*
2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "TableCellEnumerationEditor.h"
8 #include "EnumerationValue.h"
9 #include "Type.h"
12 TableCellEnumerationEditor::TableCellEnumerationEditor(::Value* initialValue,
13 ValueFormatter* formatter)
15 TableCellOptionPopUpEditor(initialValue, formatter)
20 TableCellEnumerationEditor::~TableCellEnumerationEditor()
25 status_t
26 TableCellEnumerationEditor::ConfigureOptions()
28 EnumerationValue* initialValue = dynamic_cast<EnumerationValue*>(
29 InitialValue());
30 if (initialValue == NULL)
31 return B_BAD_VALUE;
33 EnumerationType* type = initialValue->GetType();
34 for (int32 i = 0; i < type->CountValues(); i++) {
35 EnumeratorValue* value = type->ValueAt(i);
36 BString output;
38 status_t error = AddOption(value->Name(), value->Value().ToInt32());
39 if (error != B_OK)
40 return error;
43 BVariant integerValue;
44 if (!initialValue->ToVariant(integerValue))
45 return B_NO_MEMORY;
47 SelectOptionFor(integerValue.ToInt32());
49 return B_OK;
53 status_t
54 TableCellEnumerationEditor::GetSelectedValue(::Value*& _value) const
56 EnumerationValue* initialValue = dynamic_cast<EnumerationValue*>(
57 InitialValue());
58 EnumerationType* type = initialValue->GetType();
59 const char* name = NULL;
60 int32 selectedValue = 0;
61 SelectedOption(&name, &selectedValue);
63 EnumerationValue* value = new(std::nothrow) EnumerationValue(type,
64 BVariant(selectedValue));
65 if (value == NULL)
66 return B_NO_MEMORY;
68 _value = value;
69 return B_OK;