📄 template_dictionary.h
字号:
const template_modifiers::TemplateModifier& escfn); void SetEscapedFormattedValue(const TemplateString variable, const template_modifiers::TemplateModifier& escfn, const char* format, ...)#if 0 __attribute__((__format__ (__printf__, 4, 5)))#endif ; // starts at 4 because of implicit 1st arg 'this' void SetEscapedValueAndShowSection(const TemplateString variable, const TemplateString value, const template_modifiers::TemplateModifier& escfn, const TemplateString section_name); static const template_modifiers::HtmlEscape& html_escape; static const template_modifiers::PreEscape& pre_escape; static const template_modifiers::XmlEscape& xml_escape; static const template_modifiers::JavascriptEscape& javascript_escape; static const template_modifiers::UrlQueryEscape& url_query_escape; static const template_modifiers::JsonEscape& json_escape; private: friend class SectionTemplateNode; // for access to GetSectionValue(), etc. friend class TemplateTemplateNode; // for access to GetSectionValue(), etc. friend class VariableTemplateNode; // for access to GetSectionValue(), etc. // For unittesting code using a TemplateDictionary. friend class TemplateDictionaryPeer; // TODO(csilvers): get these classes to use the peer class friend class TemplateDictionaryUnittest; friend class TemplateSetGlobalsUnittest; // This is a helper function to insert <key,value> into m. // Normally, we'd just use m[key] == value, but hash_map rules // require default constructor to be public for that to compile, and // we'd rather now allow that. template<typename ValueType> static void HashInsert(stdext::hash_map<TemplateId, ValueType, ctemplate::TemplateIdHasher>* m, TemplateString key, ValueType value); // TODO(csilvers): change this to TemplateDictionary when // we Get*Dictionaries() no longer returns a DictVector typedef std::vector<TemplateDictionary *> DictVector; typedef stdext::hash_map<TemplateId, TemplateString, ctemplate::TemplateIdHasher> VariableDict; typedef stdext::hash_map<TemplateId, DictVector*, ctemplate::TemplateIdHasher> SectionDict; typedef stdext::hash_map<TemplateId, DictVector*, ctemplate::TemplateIdHasher> IncludeDict; // This is used only for global_dict_, which is just like a VariableDict typedef stdext::hash_map<TemplateId, TemplateString, ctemplate::TemplateIdHasher> GlobalDict; // Constructor created for all children dictionaries. This includes // both a pointer to the parent dictionary and also the the // template-global dictionary from which all children (both // IncludeDictionary and SectionDictionary) inherit. Values are // filled into global_template_dict via SetTemplateGlobalValue. explicit TemplateDictionary(const std::string& name, class UnsafeArena* arena, TemplateDictionary* parent_dict, TemplateDictionary* template_global_dict_owner); // Helps set up the static stuff static GlobalDict* SetupGlobalDictUnlocked(); // Utility functions for copying a string into the arena. TemplateString Memdup(const char* s, size_t slen); TemplateString Memdup(const TemplateString& s) { if (s.is_immutable()) { return s; } return Memdup(s.ptr_, s.length_); } // Used for recursive MakeCopy calls. TemplateDictionary* InternalMakeCopy(const std::string& name_of_copy, UnsafeArena* arena); // Must be called whenever we add a value to one of the dictionaries above, // to ensure that we can reconstruct the id -> string mapping. static void AddToIdToNameMap(TemplateId id, const TemplateString& str); // Used to do the formatting for the SetFormatted*() functions static int StringAppendV(char* space, char** out, const char* format, va_list ap); // How Template::Expand() and its children access the template-dictionary. // TODO(csilvers): have GetSectionValue return a TemplateString. const char *GetSectionValue(const TemplateString& variable) const; bool IsHiddenSection(const TemplateString& name) const; const DictVector& GetDictionaries(const TemplateString& section_name) const; bool IsHiddenTemplate(const TemplateString& name) const; const char *GetIncludeTemplateName(const TemplateString& variable, int dictnum) const; const DictVector& GetTemplateDictionaries( const TemplateString& include_name) const; // CreateTemplateIerator // This is SectionIterator exactly, just with a different name to // self-document the fact the value applies to a template include. // Caller frees return value. virtual TemplateDictionaryInterface::IteratorProxy CreateTemplateIterator( const TemplateString& section_name) const; // CreateSectionIterator // Factory method implementation that constructs a iterator representing the // set of dictionaries associated with a secion name, if any. This // implementation checks the local dictionary itself, not the template-wide // dictionary or the global dictionary. // Caller frees return value. virtual TemplateDictionaryInterface::IteratorProxy CreateSectionIterator( const TemplateString& section_name) const; // TemplateDictionary-specific implementation of dictionary iterators. class Iterator : public TemplateDictionaryInterface::Iterator { protected: friend class TemplateDictionary; Iterator(DictVector::const_iterator begin, DictVector::const_iterator end) : begin_(begin), end_(end) { } public: virtual ~Iterator() { } virtual bool HasNext() const; virtual const TemplateDictionaryInterface& Next(); private: DictVector::const_iterator begin_; const DictVector::const_iterator end_; }; // The "name" of the dictionary for debugging output (Dump, etc.) // The arena, also set at construction time. class UnsafeArena* const arena_; bool should_delete_arena_; // only true if we 'new arena' in constructor const char* const name_; // points into the arena // The three dictionaries that I own -- for vars, sections, and template-incs VariableDict* variable_dict_; SectionDict* section_dict_; IncludeDict* include_dict_; // Like variable_dict_, but persists across template-includes. // Unlike the global dict in that only this template and its // children get to see the values. So it's halfway in between. For // the parent-template, template_global_dict_ is not NULL, and // template_global_dict_owner_ is this. For all of its children, // template_global_dict_ is NULL, and template_global_dict_owner_ // points to the root parent-template (the one with the non-NULL // template_global_dict_). VariableDict* template_global_dict_; TemplateDictionary* template_global_dict_owner_; // My parent dictionary, used when variable lookups at this level fail. // Note this is only for *variables*, not sections or templates. TemplateDictionary* parent_dict_; // The static, global dictionary, at the top of the parent-dictionary chain static GlobalDict* global_dict_; // The filename associated with this dictionary. If set, this declares // what template the dictionary is supposed to be expanded with. Required // for template-includes, optional (but useful) for 'normal' dicts. const char* filename_; private: // Can't invoke copy constructor or assignment operator TemplateDictionary(const TemplateDictionary&); void operator=(const TemplateDictionary&);};}#endif // TEMPLATE_TEMPLATE_DICTIONARY_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -