Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate bitset constructors and swap #313

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions ridlbe/c++11/templates/cli/hdr/bitset.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@ public:
<%= cxxname %> (<%= cxxname %>&&) = default;
<%= cxxname %>& operator= (const <%= cxxname %>&) = default;
<%= cxxname %>& operator= (<%= cxxname %>&&) = default;
%unless base.nil?
using <%= base.cxxname %>::<%= base.cxxname %>;
%end
%_ms = bitfields.dup.find_all {|bitf| !bitf.cxxname.empty? }
/// Constructor which accepts value for all members
explicit inline <%= cxxname %> (
%unless base.nil?
<%= base.cxxname %> _base<%= _ms.empty? ? ');' : ',' %>
%end
%unless _ms.empty?
% while !_ms.empty?
% _m = _ms.shift
<%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ');' : ',' %>
% end
%end

%bitfields.each do |_m|
% unless _m.cxxname.empty?
%bitfields.find_all {|bitf| !bitf.cxxname.empty? }.each do |_m|
inline void <%= _m.cxxname %> (<%= _m.cxx_in_type %> _x11_<%= _m.cxxname %>) { this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %> = _x11_<%= _m.cxxname %>; }
inline <%= _m.cxx_in_type %> <%= _m.cxxname %> () const { return this->_taox11_<%= cxxname.downcase %>.<%= _m.cxxname %>; }
% end
%end

/// Exchange the value of two bitsets in an efficient matter
inline void swap (<%= cxx_inout_type %> s);

private:
struct
{
Expand All @@ -29,4 +45,6 @@ private:
} _taox11_<%= cxxname.downcase %>;
}; // <%= cxxname %>

inline void swap (<%= scoped_cxx_out_type %> m1, <%= scoped_cxx_out_type %> m2) { m1.swap (m2); }

% visit_template('typecode') if generate_typecode_support?
37 changes: 37 additions & 0 deletions ridlbe/c++11/templates/cli/inl/bitset_inl.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// generated from <%= ridl_template_path %>
%#
%# Constructor inlines
%#
%# Initializer CTOR
%_ms = bitfields.dup.find_all {|bitf| !bitf.cxxname.empty? }
inline <%= scoped_cxxtype %>::<%= cxxname %> (
% unless base.nil?
<%= base.cxxname %> _base<%= _ms.empty? ? ')' : ',' %>
% end
% unless _ms.empty?
% while !_ms.empty?
% _m = _ms.shift
<%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %>
% end
% end
% _pfx = nil
% unless base.nil?
: <%= base.cxxname %> (std::move(_base))<% unless _ms.empty? %>,<% end %>
% end
% str = ""
% bitfields.find_all {|bitf| !bitf.cxxname.empty? }.each do |_m|
% str = "#{str}#{_pfx}#{_m.cxxname}"
% _pfx = ', ' unless _pfx
% end
<% if base.nil? %>:<% else %>,<% end %> _taox11_<%= cxxname.downcase %> { <%= str %> }
{
}

inline void <%= scoped_cxxtype %>::swap (<%= scoped_cxx_out_type %> s)
{
%# Add support for base
%# bitfields.each do |_m|
std::swap (this->_taox11_<%= cxxname.downcase %>, s._taox11_<%= cxxname.downcase %>);
%# end
}
4 changes: 4 additions & 0 deletions ridlbe/c++11/writers/stubheader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ def enter_struct(node)
visitor(StructVisitor).visit_inl(node)
end

def visit_bitset(node)
visitor(BitsetVisitor).visit_inl(node)
end

def enter_union(node)
visitor(UnionVisitor).visit_inl(node)
end
Expand Down
Loading