1// Filename: File.ipp 2namespace dclass // open namespace 3{ 4 5 6inline Import::Import(const std::string& module_name) : 7 module(module_name) 8{ 9} 10 11 12// get_num_classes returns the number of classes in the file 13inline size_t File::get_num_classes() const 14{ 15 return m_classes.size(); 16} 17// get_class returns the <n>th class read from the .dc file(s). 18inline Class* File::get_class(unsigned int n) 19{ 20 return m_classes.at(n); 21} 22inline const Class* File::get_class(unsigned int n) const 23{ 24 return m_classes.at(n); 25} 26 27// get_num_structs returns the number of structs in the file. 28inline size_t File::get_num_structs() const 29{ 30 return m_structs.size(); 31} 32// get_struct returns the <n>th struct in the file. 33inline Struct* File::get_struct(unsigned int n) 34{ 35 return m_structs.at(n); 36} 37inline const Struct* File::get_struct(unsigned int n) const 38{ 39 return m_structs.at(n); 40} 41 42// get_num_types returns the number of types in the file. 43// All type ids will be within the range 0 <= id < get_num_types(). 44inline size_t File::get_num_types() const 45{ 46 return m_types_by_id.size(); 47} 48 49// get_type_by_id returns the requested type or nullptr if there is no such type. 50inline DistributedType* File::get_type_by_id(unsigned int id) 51{ 52 if(id < m_types_by_id.size()) 53 { 54 return m_types_by_id[id]; 55 } 56 57 return nullptr; 58} 59inline const DistributedType* File::get_type_by_id(unsigned int id) const 60{ 61 if(id < m_types_by_id.size()) 62 { 63 return m_types_by_id[id]; 64 } 65 66 return nullptr; 67} 68// get_type_by_name returns the requested type or nullptr if there is no such type. 69inline DistributedType* File::get_type_by_name(const std::string &name) 70{ 71 auto type_ref = m_types_by_name.find(name); 72 if(type_ref != m_types_by_name.end()) 73 { 74 return type_ref->second; 75 } 76 77 return nullptr; 78} 79inline const DistributedType* File::get_type_by_name(const std::string &name) const 80{ 81 auto type_ref = m_types_by_name.find(name); 82 if(type_ref != m_types_by_name.end()) 83 { 84 return type_ref->second; 85 } 86 87 return nullptr; 88} 89 90// get_field_by_id returns the request field or nullptr if there is no such field. 91inline Field* File::get_field_by_id(unsigned int id) 92{ 93 if(id < m_fields_by_id.size()) 94 { 95 return m_fields_by_id[id]; 96 } 97 98 return nullptr; 99} 100inline const Field* File::get_field_by_id(unsigned int id) const 101{ 102 if(id < m_fields_by_id.size()) 103 { 104 return m_fields_by_id[id]; 105 } 106 107 return nullptr; 108} 109 110// get_num_imports returns the number of imports in the file. 111inline size_t File::get_num_imports() const 112{ 113 return m_imports.size(); 114} 115// get_import retuns the <n>th import in the file. 116inline Import* File::get_import(unsigned int n) 117{ 118 return m_imports.at(n); 119} 120inline const Import* File::get_import(unsigned int n) const 121{ 122 return m_imports.at(n); 123} 124 125// has_keyword returns true if a keyword with the name <keyword> is declared in the file. 126inline bool File::has_keyword(const std::string& keyword) const 127{ 128 for(auto it = m_keywords.begin(); it != m_keywords.end(); ++it) 129 { 130 if(*it == keyword) 131 { 132 return true; 133 } 134 } 135 return false; 136} 137// get_num_keywords returns the number of keywords declared in the file. 138inline size_t File::get_num_keywords() const 139{ 140 return m_keywords.size(); 141} 142// get_keyword returns the <n>th keyword declared in the file. 143inline const std::string& File::get_keyword(unsigned int n) const 144{ 145 return m_keywords.at(n); 146} 147 148 149} // close namespace dclass 150