00001 class __meta_table_enum_wrapper {
00002 public:
00003 __meta_table_enum_wrapper(file_info & p_info) : m_info(p_info) {}
00004 template<typename t_values>
00005 void operator() (const char * p_name,const t_values & p_values) {
00006 t_size index = infinite;
00007 for(t_values::const_iterator iter = p_values.first(); iter.is_valid(); ++iter) {
00008 if (index == infinite) index = m_info.__meta_add_unsafe(p_name,*iter);
00009 else m_info.meta_add_value(index,*iter);
00010 }
00011 }
00012 private:
00013 file_info & m_info;
00014 };
00015
00017 class meta_table_builder {
00018 public:
00019 typedef pfc::chain_list_v2_t<pfc::string8> t_entry;
00020 typedef pfc::map_t<pfc::string8,t_entry,file_info::field_name_comparator> t_content;
00021
00022 t_content & content() {return m_data;}
00023 t_content const & content() const {return m_data;}
00024
00025 void add(const char * p_name,const char * p_value,t_size p_value_len = infinite) {
00026 if (file_info::g_is_valid_field_name(p_name)) {
00027 __add(p_name).insert_last()->set_string(p_value,p_value_len);
00028 }
00029 }
00030
00031 void remove(const char * p_name) {
00032 m_data.remove(p_name);
00033 }
00034 void set(const char * p_name,const char * p_value,t_size p_value_len = infinite) {
00035 if (file_info::g_is_valid_field_name(p_name)) {
00036 t_entry & entry = __add(p_name);
00037 entry.remove_all();
00038 entry.insert_last()->set_string(p_value,p_value_len);
00039 }
00040 }
00041 t_entry & add(const char * p_name) {
00042 if (!file_info::g_is_valid_field_name(p_name)) throw pfc::exception_bug_check_v2();
00043 return __add(p_name);
00044 }
00045 void finalize(file_info & p_info) const {
00046 p_info.meta_remove_all();
00047 m_data.enumerate(__meta_table_enum_wrapper(p_info));
00048 }
00049
00050 void from_info(const file_info & p_info) {
00051 m_data.remove_all();
00052 from_info_overwrite(p_info);
00053 }
00054 void from_info_overwrite(const file_info & p_info) {
00055 for(t_size metawalk = 0, metacount = p_info.meta_get_count(); metawalk < metacount; ++metawalk ) {
00056 const t_size valuecount = p_info.meta_enum_value_count(metawalk);
00057 if (valuecount > 0) {
00058 t_entry & entry = add(p_info.meta_enum_name(metawalk));
00059 entry.remove_all();
00060 for(t_size valuewalk = 0; valuewalk < valuecount; ++valuewalk) {
00061 entry.insert_last(p_info.meta_enum_value(metawalk,valuewalk));
00062 }
00063 }
00064 }
00065 }
00066 void reset() {m_data.remove_all();}
00067 private:
00068
00069 t_entry & __add(const char * p_name) {
00070 return m_data.find_or_add(p_name);
00071 }
00072
00073 t_content m_data;
00074 };