| 
									
										
										
										
											2016-04-18 23:33:43 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  | This file is part of Telegram Desktop, | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | the official desktop application for the Telegram messaging service. | 
					
						
							| 
									
										
										
										
											2016-04-18 23:33:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | For license and copyright information please follow this link: | 
					
						
							|  |  |  | https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					
						
							| 
									
										
										
										
											2016-04-18 23:33:43 +03:00
										 |  |  | */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QtCore/QString>
 | 
					
						
							|  |  |  | #include <QtCore/QList>
 | 
					
						
							|  |  |  | #include <QtCore/QMap>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include "codegen/style/structure_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace codegen { | 
					
						
							|  |  |  | namespace style { | 
					
						
							|  |  |  | namespace structure { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Module { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	explicit Module(const QString &fullpath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QString filepath() const { | 
					
						
							|  |  |  | 		return fullpath_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void addIncluded(std::unique_ptr<Module> &&value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool hasIncludes() const { | 
					
						
							|  |  |  | 		return !included_.empty(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	template <typename F> | 
					
						
							|  |  |  | 	bool enumIncludes(F functor) const { | 
					
						
							|  |  |  | 		for (const auto &module : included_) { | 
					
						
							|  |  |  | 			if (!functor(*module)) { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Returns false if there is a struct with such name already.
 | 
					
						
							|  |  |  | 	bool addStruct(const Struct &value); | 
					
						
							|  |  |  | 	// Returns nullptr if there is no such struct in result_ or any of included modules.
 | 
					
						
							|  |  |  | 	const Struct *findStruct(const FullName &name) const; | 
					
						
							|  |  |  | 	bool hasStructs() const { | 
					
						
							|  |  |  | 		return !structs_.isEmpty(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	template <typename F> | 
					
						
							|  |  |  | 	bool enumStructs(F functor) const { | 
					
						
							|  |  |  | 		for (const auto &value : structs_) { | 
					
						
							|  |  |  | 			if (!functor(value)) { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Returns false if there is a variable with such name already.
 | 
					
						
							|  |  |  | 	bool addVariable(const Variable &value); | 
					
						
							|  |  |  | 	// Returns nullptr if there is no such variable in result_ or any of included modules.
 | 
					
						
							| 
									
										
										
										
											2016-06-20 14:31:12 +03:00
										 |  |  | 	const Variable *findVariable(const FullName &name, bool *outFromThisModule = nullptr) const; | 
					
						
							| 
									
										
										
										
											2016-04-18 23:33:43 +03:00
										 |  |  | 	bool hasVariables() const { | 
					
						
							|  |  |  | 		return !variables_.isEmpty(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	template <typename F> | 
					
						
							|  |  |  | 	bool enumVariables(F functor) const { | 
					
						
							|  |  |  | 		for (const auto &value : variables_) { | 
					
						
							|  |  |  | 			if (!functor(value)) { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	explicit operator bool() const { | 
					
						
							|  |  |  | 		return !fullpath_.isEmpty(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 21:05:46 +03:00
										 |  |  | 	const Struct *findStructInModule(const FullName &name, const Module &module) const; | 
					
						
							|  |  |  | 	const Variable *findVariableInModule(const FullName &name, const Module &module) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-18 23:33:43 +03:00
										 |  |  | private: | 
					
						
							|  |  |  | 	QString fullpath_; | 
					
						
							|  |  |  | 	std::vector<std::unique_ptr<Module>> included_; | 
					
						
							|  |  |  | 	QList<Struct> structs_; | 
					
						
							|  |  |  | 	QList<Variable> variables_; | 
					
						
							|  |  |  | 	QMap<QString, int> structsByName_; | 
					
						
							|  |  |  | 	QMap<QString, int> variablesByName_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace structure
 | 
					
						
							|  |  |  | } // namespace style
 | 
					
						
							|  |  |  | } // namespace codegen
 |