Skip to content

Commit

Permalink
Merge pull request #313 from jwillemsen/jwi-bitsetconstructor
Browse files Browse the repository at this point in the history
Generate bitset constructors and swap
  • Loading branch information
jwillemsen authored Aug 14, 2023
2 parents 72be7f5 + 9a7df9e commit f16805c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
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

0 comments on commit f16805c

Please sign in to comment.