Another SimpleVector down.

This commit is contained in:
2025-08-10 22:49:36 -04:00
parent 6b3eb54b09
commit 47d9c7eaa0

View File

@ -213,12 +213,12 @@ public:
class DilloHtmlSelect {
friend class DilloHtmlInput;
private:
lout::misc::SimpleVector<DilloHtmlOptbase *> *opts;
DilloHtmlSelect ();
std::vector< std::unique_ptr< DilloHtmlOptbase > > opts;
DilloHtmlSelect ()= default;
public:
~DilloHtmlSelect ();
DilloHtmlOptbase *getCurrentOpt ();
void addOpt (DilloHtmlOptbase *opt);
void addOpt (std::unique_ptr< DilloHtmlOptbase > opt);
void ensureSelection ();
void addOptsTo (SelectionResource *res);
void reset (SelectionResource *res);
@ -813,10 +813,9 @@ void Html_tag_open_optgroup(DilloHtml *html, const char *tag, int tagsize)
label = "";
}
DilloHtmlOptgroup *opt =
new DilloHtmlOptgroup (dStrdup(label.value().c_str()), enabled);
auto opt= std::make_unique< DilloHtmlOptgroup >( dStrdup( label.value().c_str() ), enabled );
input->select->addOpt(opt);
input->select->addOpt( std::move( opt ) );
}
}
@ -834,9 +833,9 @@ void Html_tag_close_optgroup(DilloHtml *html)
if (input &&
(input->type == DILLO_HTML_INPUT_SELECT ||
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
DilloHtmlOptgroupClose *opt = new DilloHtmlOptgroupClose ();
auto opt= std::make_unique< DilloHtmlOptgroupClose >();
input->select->addOpt(opt);
input->select->addOpt( std::move( opt ) );
}
}
}
@ -863,10 +862,10 @@ void Html_tag_open_option(DilloHtml *html, const char *tag, int tagsize)
bool selected = (a_Html_get_attr(html, tag, tagsize,"selected") != NULL);
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
DilloHtmlOption *option =
new DilloHtmlOption (value ? dStrdup( value.value().c_str() ) : nullptr, label ? dStrdup( label.value().c_str() ) : nullptr, selected, enabled);
auto option =
std::make_unique< DilloHtmlOption >(value ? dStrdup( value.value().c_str() ) : nullptr, label ? dStrdup( label.value().c_str() ) : nullptr, selected, enabled );
input->select->addOpt(option);
input->select->addOpt( std::move( option ) );
}
a_Html_stash_init(html);
@ -1833,35 +1832,17 @@ void DilloHtmlInput::reset ()
* DilloHtmlSelect
*/
/*
* Constructor
*/
DilloHtmlSelect::DilloHtmlSelect ()
DilloHtmlOptbase *
DilloHtmlSelect::getCurrentOpt()
{
opts = new misc::SimpleVector<DilloHtmlOptbase *> (4);
return opts.back().get();
}
/*
* Destructor
*/
DilloHtmlSelect::~DilloHtmlSelect ()
void
DilloHtmlSelect::addOpt( std::unique_ptr< DilloHtmlOptbase > opt )
{
int size = opts->size ();
for (int k = 0; k < size; k++)
delete opts->get (k);
delete opts;
}
DilloHtmlOptbase *DilloHtmlSelect::getCurrentOpt ()
{
return opts->get (opts->size() - 1);
}
void DilloHtmlSelect::addOpt (DilloHtmlOptbase *opt)
{
int size = opts->size ();
opts->increase ();
opts->set (size, opt);
opts.push_back( std::move( opt ) );
}
/**
@ -1869,15 +1850,15 @@ void DilloHtmlSelect::addOpt (DilloHtmlOptbase *opt)
*/
void DilloHtmlSelect::ensureSelection()
{
int size = opts->size ();
int size = opts.size ();
if (size > 0) {
for (int i = 0; i < size; i++) {
DilloHtmlOptbase *opt = opts->get (i);
DilloHtmlOptbase *opt = opts.at (i).get();
if (opt->isSelected())
return;
}
for (int i = 0; i < size; i++) {
DilloHtmlOptbase *opt = opts->get (i);
DilloHtmlOptbase *opt = opts.at (i).get();
if (opt->select())
break;
}
@ -1886,28 +1867,28 @@ void DilloHtmlSelect::ensureSelection()
void DilloHtmlSelect::addOptsTo (SelectionResource *res)
{
int size = opts->size ();
int size = opts.size ();
for (int i = 0; i < size; i++) {
DilloHtmlOptbase *opt = opts->get (i);
DilloHtmlOptbase *opt = opts.at (i).get();
opt->addSelf(res);
}
}
void DilloHtmlSelect::reset (SelectionResource *res)
{
int size = opts->size ();
int size = opts.size ();
for (int i = 0; i < size; i++) {
DilloHtmlOptbase *opt = opts->get (i);
DilloHtmlOptbase *opt = opts.at (i).get();
res->setItem(i, opt->isSelected());
}
}
void DilloHtmlSelect::appendValuesTo (std::vector< std::string > &values, SelectionResource *res)
{
int size = opts->size ();
int size = opts.size ();
for (int i = 0; i < size; i++) {
if (res->isSelected (i)) {
DilloHtmlOptbase *opt = opts->get (i);
DilloHtmlOptbase *opt = opts.at (i).get();
const char *val = opt->getValue();
if (val)