This source file includes following definitions.
- Get
- set_data
- data
- key
- data_
- Data
- GetValue
- Key
#include "ui/base/view_prop.h"
#include <set>
namespace ui {
class ViewProp::Data : public base::RefCounted<ViewProp::Data> {
public:
static void Get(gfx::AcceleratedWidget view,
const char* key,
bool create,
scoped_refptr<Data>* data) {
if (!data_set_)
data_set_ = new DataSet;
scoped_refptr<Data> new_data(new Data(view, key));
DataSet::const_iterator i = data_set_->find(new_data.get());
if (i != data_set_->end()) {
*data = *i;
return;
}
if (!create)
return;
data_set_->insert(new_data.get());
*data = new_data.get();
}
void set_data(void* data) { data_ = data; }
void* data() const { return data_; }
const char* key() const { return key_; }
private:
friend class base::RefCounted<Data>;
class DataComparator {
public:
bool operator()(const Data* d1, const Data* d2) const {
return (d1->view_ == d2->view_) ? (d1->key_ < d2->key_) :
(d1->view_ < d2->view_);
}
};
typedef std::set<Data*, DataComparator> DataSet;
Data(gfx::AcceleratedWidget view, const char* key)
: view_(view),
key_(key),
data_(NULL) {}
~Data() {
DataSet::iterator i = data_set_->find(this);
if (i != data_set_->end() && *i == this)
data_set_->erase(i);
}
static DataSet* data_set_;
const gfx::AcceleratedWidget view_;
const char* key_;
void* data_;
DISALLOW_COPY_AND_ASSIGN(Data);
};
ViewProp::Data::DataSet* ViewProp::Data::data_set_ = NULL;
ViewProp::ViewProp(gfx::AcceleratedWidget view, const char* key, void* data) {
Data::Get(view, key, true, &data_);
data_->set_data(data);
}
ViewProp::~ViewProp() {
data_->set_data(NULL);
}
void* ViewProp::GetValue(gfx::AcceleratedWidget view, const char* key) {
scoped_refptr<Data> data;
Data::Get(view, key, false, &data);
return data.get() ? data->data() : NULL;
}
const char* ViewProp::Key() const {
return data_->key();
}
}