<commit_before><% require './ranges' %>
<% define 'Tree', :for => this do %>
	#include <server/device_tree.tpp>
	#include <data/base.hpp>
	#include <data/base_string.h>
	#include <data/base_number.hpp>
	#include <data/base_boolean.h>
	#include <data/base_floating.hpp>
	#include <stdint.h>
	#include <string>
	#include <cmath>
	
	<%nl%>
	namespace ouroboros
	{<%iinc%>
		namespace detail
		{<%iinc%>
			template<>
			group<var_field> build_tree()
			{<%iinc%>		
				group<var_field> result("server", "Root node.");
				<% 
					expand 'Field', :foreach => field
					expand 'Group', :foreach => group
					expand 'AddGroup', :foreach => group
				%>
				<%nl%>
				return result;
			<%idec%>}
		<%idec%>}
	<%idec%>}
<% end %>

<% define 'Field', :for => this do %>
	<%
		if parent.class.to_s === ServerModel::DeviceConfig.to_s  
			parentGroupVar = 'result'
			operator = '.'
		
		else
			parentGroupVar = parent.title.chardata[0].strip.downcase.delete(' ')
			operator = '->'
		end
	%>
	<%= parentGroupVar %><%= operator %>add(new <%nonl%><%nows%>
	<%
		if type =~ /(un)?signed(Int|Short|Byte)Field/ or type === "intField"
			class << this
				attr_accessor :Type;
				attr_accessor :Min;
				attr_accessor :Max;
			end
			
			# set the bit size of the integer based on type
			case type 
			when /Int/ then this.Type = "int32_t"
			when /Short/ then this.Type = "int16_t"
			when /Byte/ then this.Type = "int8_t"
			end

			# if it is unsigned make it a uint
			this.Type.prepend "u" if this.Type =~ /unsigned/
			
			# set min and max based on predefined constants
			this.Min = Object.const_get("#{type}_MIN".upcase)
			this.Max = Object.const_get("#{type}_MAX".upcase)

			expand 'numberField::Field', :for => this 
			
		elsif type === "stringField"
			expand 'stringField::Field', :for => this
		elsif type =~ /(double|float)Field/
			class << this
				attr_accessor :Type;
				attr_accessor :Min;
				attr_accessor :Max;
			end
			
			if type === "doubleField"	
				this.Type = "double"
				this.Min = DOUBLEFIELD_MIN
				this.Max = DOUBLEFIELD_MAX
			elsif type === "floatField"
				this.Type = "float"
				this.Min = FLOATFIELD_MIN
				this.Max = FLOATFIELD_MAX
			end
			expand 'floatingField::Field', :for => this
			
		elsif type == "enumField"
			expand 'enumField::Field', :for => this
		elsif type === "booleanField"
			expand 'booleanField::Field', :for => this
		end
	%>
	);
<% end %>

<% define 'Group', :for => this do %>
	<% groupVar = title.chardata[0].strip.downcase.delete(' ') %>
	group<var_field> *<%= groupVar %> = new group<var_field>("<%= title.chardata[0].strip %>", "<%= description.chardata[0].strip %>");	
	<% expand 'Field', :foreach => field %>
	<% expand 'Group', :foreach => group %>
	<% expand 'AddGroup', :foreach => group %>
<% end %>

<% define 'AddGroup', :for => this do %>
	<% groupVar = title.chardata[0].strip.downcase.delete(' ') %>
	<% if parent.class.to_s != ServerModel::DeviceConfig.to_s %>
		<%= parent.title.chardata[0].strip.downcase.delete(' ') %>->add(<%= groupVar %>);
	<% else %>
		result.add(<%= groupVar %>);
	<% end %>
<% end %><commit_msg>Generator adds groups and fields in correct order.<commit_after><% require './ranges' %>
<% define 'Tree', :for => this do %>
	#include <server/device_tree.tpp>
	#include <data/base.hpp>
	#include <data/base_string.h>
	#include <data/base_number.hpp>
	#include <data/base_boolean.h>
	#include <data/base_floating.hpp>
	#include <stdint.h>
	#include <string>
	#include <cmath>
	
	<%nl%>
	namespace ouroboros
	{<%iinc%>
		namespace detail
		{<%iinc%>
			template<>
			group<var_field> build_tree()
			{<%iinc%>		
				group<var_field> result("server", "Root node.");
				<%
					this.eContents.each do |item|
						if item.class.to_s === ServerModel::Field.to_s
							expand 'Field', :for => item
						elsif item.class.to_s === ServerModel::Group.to_s
							expand 'Group', :for => item
							expand 'AddGroup', :for => item
						end
					end
				%>
				<%nl%>
				return result;
			<%idec%>}
		<%idec%>}
	<%idec%>}
<% end %>

<% define 'Field', :for => this do %>
	<%
		if parent.class.to_s === ServerModel::DeviceConfig.to_s  
			parentGroupVar = 'result'
			operator = '.'
		
		else
			parentGroupVar = parent.title.chardata[0].strip.downcase.delete(' ')
			operator = '->'
		end
	%>
	<%= parentGroupVar %><%= operator %>add(new <%nonl%><%nows%>
	<%
		if type =~ /(un)?signed(Int|Short|Byte)Field/ or type === "intField"
			class << this
				attr_accessor :Type;
				attr_accessor :Min;
				attr_accessor :Max;
			end
			
			# set the bit size of the integer based on type
			case type 
			when /Int/ then this.Type = "int32_t"
			when /Short/ then this.Type = "int16_t"
			when /Byte/ then this.Type = "int8_t"
			end

			# if it is unsigned make it a uint
			this.Type.prepend "u" if this.Type =~ /unsigned/
			
			# set min and max based on predefined constants
			this.Min = Object.const_get("#{type}_MIN".upcase)
			this.Max = Object.const_get("#{type}_MAX".upcase)

			expand 'numberField::Field', :for => this 
			
		elsif type === "stringField"
			expand 'stringField::Field', :for => this
		elsif type =~ /(double|float)Field/
			class << this
				attr_accessor :Type;
				attr_accessor :Min;
				attr_accessor :Max;
			end
			
			if type === "doubleField"	
				this.Type = "double"
				this.Min = DOUBLEFIELD_MIN
				this.Max = DOUBLEFIELD_MAX
			elsif type === "floatField"
				this.Type = "float"
				this.Min = FLOATFIELD_MIN
				this.Max = FLOATFIELD_MAX
			end
			expand 'floatingField::Field', :for => this
			
		elsif type == "enumField"
			expand 'enumField::Field', :for => this
		elsif type === "booleanField"
			expand 'booleanField::Field', :for => this
		end
	%>
	);
<% end %>

<% define 'Group', :for => this do %>
	<% groupVar = title.chardata[0].strip.downcase.delete(' ') %>
	group<var_field> *<%= groupVar %> = new group<var_field>("<%= title.chardata[0].strip %>", "<%= description.chardata[0].strip %>");	
	<%
		this.eContents.each do |item|
			if item.class.to_s === ServerModel::Field.to_s
				expand 'Field', :for => item
			elsif item.class.to_s === ServerModel::Group.to_s
				expand 'Group', :for => item
				expand 'AddGroup', :for => item
			end
		end
	%>
<% end %>

<% define 'AddGroup', :for => this do %>
	<% groupVar = title.chardata[0].strip.downcase.delete(' ') %>
	<% if parent.class.to_s != ServerModel::DeviceConfig.to_s %>
		<%= parent.title.chardata[0].strip.downcase.delete(' ') %>->add(<%= groupVar %>);
	<% else %>
		result.add(<%= groupVar %>);
	<% end %>
<% end %>
{'fraction_non_alphanumeric': 0.1791845493562232, 'fraction_numerical': 0.003372164316370325, 'mean_word_length': 3.2984189723320156, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1668060', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2337, 'n_words': 537}