cef/libcef/common/string_list_impl.cc
Sergey Markelov c3648f42b2 Use less error prone string list, map or multimap pointer types
Use pointers to incomplete struct types. If an argument of a not suitable
type is passed to a function of any string collection,
C compiler will warn:
  warning: passing argument 1 of <func> from incompatible pointer type
C++ compiler will raise an error, for example:
  error: cannot convert 'cef_string_list_t' ... to 'cef_string_multimap_t'

With the previously used `void*` pointer types, such errors in a code were not
diagnosed.
2023-04-13 16:06:02 +00:00

63 lines
1.8 KiB
C++

// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <vector>
#include "include/internal/cef_string_list.h"
#include "base/logging.h"
namespace {
using StringList = std::vector<CefString>;
} // namespace
CEF_EXPORT cef_string_list_t cef_string_list_alloc() {
return reinterpret_cast<cef_string_list_t>(new StringList);
}
CEF_EXPORT size_t cef_string_list_size(cef_string_list_t list) {
DCHECK(list);
StringList* impl = reinterpret_cast<StringList*>(list);
return impl->size();
}
CEF_EXPORT int cef_string_list_value(cef_string_list_t list,
size_t index,
cef_string_t* value) {
DCHECK(list);
DCHECK(value);
StringList* impl = reinterpret_cast<StringList*>(list);
DCHECK_LT(index, impl->size());
if (index >= impl->size()) {
return false;
}
const CefString& str = (*impl)[index];
return cef_string_copy(str.c_str(), str.length(), value);
}
CEF_EXPORT void cef_string_list_append(cef_string_list_t list,
const cef_string_t* value) {
DCHECK(list);
StringList* impl = reinterpret_cast<StringList*>(list);
impl->push_back(CefString(value));
}
CEF_EXPORT void cef_string_list_clear(cef_string_list_t list) {
DCHECK(list);
StringList* impl = reinterpret_cast<StringList*>(list);
impl->clear();
}
CEF_EXPORT void cef_string_list_free(cef_string_list_t list) {
DCHECK(list);
StringList* impl = reinterpret_cast<StringList*>(list);
delete impl;
}
CEF_EXPORT cef_string_list_t cef_string_list_copy(cef_string_list_t list) {
DCHECK(list);
StringList* impl = reinterpret_cast<StringList*>(list);
return reinterpret_cast<cef_string_list_t>(new StringList(*impl));
}