2010-10-03 23:04:50 +02:00
|
|
|
// 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.
|
|
|
|
|
2011-05-21 03:49:16 +02:00
|
|
|
#include "include/internal/cef_string_map.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
typedef std::map<CefString, CefString> StringMap;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
CEF_EXPORT cef_string_map_t cef_string_map_alloc()
|
|
|
|
{
|
|
|
|
return new StringMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_string_map_size(cef_string_map_t map)
|
|
|
|
{
|
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = (StringMap*)map;
|
|
|
|
return impl->size();
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CEF_EXPORT int cef_string_map_find(cef_string_map_t map,
|
|
|
|
const cef_string_t* key,
|
|
|
|
cef_string_t* value)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
DCHECK(map);
|
2010-11-22 18:49:46 +01:00
|
|
|
DCHECK(value);
|
2010-10-03 23:04:50 +02:00
|
|
|
StringMap* impl = (StringMap*)map;
|
2010-11-22 18:49:46 +01:00
|
|
|
StringMap::const_iterator it = impl->find(CefString(key));
|
2010-10-03 23:04:50 +02:00
|
|
|
if(it == impl->end())
|
|
|
|
return NULL;
|
2010-11-22 18:49:46 +01:00
|
|
|
const CefString& val = it->second;
|
|
|
|
return cef_string_set(val.c_str(), val.length(), value, true);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CEF_EXPORT int cef_string_map_key(cef_string_map_t map, int index,
|
|
|
|
cef_string_t* key)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
DCHECK(map);
|
2010-11-22 18:49:46 +01:00
|
|
|
DCHECK(key);
|
2010-10-03 23:04:50 +02:00
|
|
|
StringMap* impl = (StringMap*)map;
|
|
|
|
DCHECK(index >= 0 && index < (int)impl->size());
|
|
|
|
if(index < 0 || index >= (int)impl->size())
|
|
|
|
return NULL;
|
|
|
|
StringMap::const_iterator it = impl->begin();
|
|
|
|
for(int ct = 0; it != impl->end(); ++it, ct++) {
|
|
|
|
if(ct == index)
|
2010-11-22 18:49:46 +01:00
|
|
|
return cef_string_set(it->first.c_str(), it->first.length(), key, true);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
return 0;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CEF_EXPORT int cef_string_map_value(cef_string_map_t map, int index,
|
|
|
|
cef_string_t* value)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
DCHECK(map);
|
2010-11-22 18:49:46 +01:00
|
|
|
DCHECK(value);
|
2010-10-03 23:04:50 +02:00
|
|
|
StringMap* impl = (StringMap*)map;
|
|
|
|
DCHECK(index >= 0 && index < (int)impl->size());
|
|
|
|
if(index < 0 || index >= (int)impl->size())
|
|
|
|
return NULL;
|
|
|
|
StringMap::const_iterator it = impl->begin();
|
|
|
|
for(int ct = 0; it != impl->end(); ++it, ct++) {
|
2010-11-22 18:49:46 +01:00
|
|
|
if(ct == index) {
|
|
|
|
return cef_string_set(it->second.c_str(), it->second.length(), value,
|
|
|
|
true);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
return 0;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CEF_EXPORT int cef_string_map_append(cef_string_map_t map,
|
|
|
|
const cef_string_t* key,
|
|
|
|
const cef_string_t* value)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = (StringMap*)map;
|
2010-11-22 18:49:46 +01:00
|
|
|
impl->insert(std::make_pair(CefString(key), CefString(value)));
|
|
|
|
return 1;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_map_clear(cef_string_map_t map)
|
|
|
|
{
|
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = (StringMap*)map;
|
|
|
|
impl->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_map_free(cef_string_map_t map)
|
|
|
|
{
|
|
|
|
DCHECK(map);
|
|
|
|
delete (StringMap*)map;
|
|
|
|
}
|