at_coder_friends-generator-cxx_iostream 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.rubocop_todo.yml +24 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +8 -0
- data/at_coder_friends-generator-cxx_iostream.gemspec +44 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/at_coder_friends/generator/cxx_iostream.rb +260 -0
- data/lib/at_coder_friends/generator/cxx_iostream/version.rb +9 -0
- data/templates/cxx_iostream.cxx.erb +71 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5533576e8293fce4aaef4642d2320e92c172855b
|
4
|
+
data.tar.gz: c79a7842032de053e2e5e91d078ae4758538e44b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da998967374d187f020f22f502335052061171ee5c278511fb6420ebd1a65dd8e0351907c1a0d0460886dc782c39ab704425fcaf0924332f4739f783c7127bc7
|
7
|
+
data.tar.gz: 2a427f1cceccbab922d6a6e546f09e40ddf7953f332e2e9a31880dc2d75345482fd855c3e389945506a4fa344057eee6bfe6b477b4aa3717bb40924bc9278f47
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Metrics/AbcSize:
|
2
|
+
Max: 20
|
3
|
+
|
4
|
+
Metrics/MethodLength:
|
5
|
+
Max: 15
|
6
|
+
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Max: 125
|
9
|
+
|
10
|
+
# enable new cops to avoid warnings
|
11
|
+
Lint/RaiseException:
|
12
|
+
Enabled: true
|
13
|
+
|
14
|
+
Lint/StructNewOverride:
|
15
|
+
Enabled: true
|
16
|
+
|
17
|
+
Style/HashEachMethods:
|
18
|
+
Enabled: true
|
19
|
+
|
20
|
+
Style/HashTransformKeys:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
Style/HashTransformValues:
|
24
|
+
Enabled: true
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nejiko2006@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
at_coder_friends-generator-cxx_iostream (0.1.0)
|
5
|
+
at_coder_friends (~> 0.6.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
at_coder_friends (0.6.6)
|
13
|
+
colorize (~> 0.8.1)
|
14
|
+
launchy (>= 2.4.3, < 2.6.0)
|
15
|
+
mechanize (~> 2.0)
|
16
|
+
colorize (0.8.1)
|
17
|
+
connection_pool (2.2.2)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
docile (1.3.2)
|
20
|
+
domain_name (0.5.20190701)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
http-cookie (1.0.3)
|
23
|
+
domain_name (~> 0.5)
|
24
|
+
json (2.3.0)
|
25
|
+
launchy (2.4.3)
|
26
|
+
addressable (~> 2.3)
|
27
|
+
mechanize (2.7.6)
|
28
|
+
domain_name (~> 0.5, >= 0.5.1)
|
29
|
+
http-cookie (~> 1.0)
|
30
|
+
mime-types (>= 1.17.2)
|
31
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
32
|
+
net-http-persistent (>= 2.5.2)
|
33
|
+
nokogiri (~> 1.6)
|
34
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
35
|
+
webrobots (>= 0.0.9, < 0.2)
|
36
|
+
mime-types (3.3.1)
|
37
|
+
mime-types-data (~> 3.2015)
|
38
|
+
mime-types-data (3.2020.0512)
|
39
|
+
mini_portile2 (2.4.0)
|
40
|
+
net-http-digest_auth (1.4.1)
|
41
|
+
net-http-persistent (4.0.0)
|
42
|
+
connection_pool (~> 2.2)
|
43
|
+
nokogiri (1.10.9)
|
44
|
+
mini_portile2 (~> 2.4.0)
|
45
|
+
ntlm-http (0.1.1)
|
46
|
+
public_suffix (4.0.5)
|
47
|
+
rake (13.0.1)
|
48
|
+
rspec (3.9.0)
|
49
|
+
rspec-core (~> 3.9.0)
|
50
|
+
rspec-expectations (~> 3.9.0)
|
51
|
+
rspec-mocks (~> 3.9.0)
|
52
|
+
rspec-core (3.9.2)
|
53
|
+
rspec-support (~> 3.9.3)
|
54
|
+
rspec-expectations (3.9.2)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.9.0)
|
57
|
+
rspec-mocks (3.9.1)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.9.0)
|
60
|
+
rspec-support (3.9.3)
|
61
|
+
simplecov (0.17.1)
|
62
|
+
docile (~> 1.1)
|
63
|
+
json (>= 1.8, < 3)
|
64
|
+
simplecov-html (~> 0.10.0)
|
65
|
+
simplecov-html (0.10.2)
|
66
|
+
unf (0.1.4)
|
67
|
+
unf_ext
|
68
|
+
unf_ext (0.0.7.7)
|
69
|
+
webrobots (0.1.2)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
at_coder_friends-generator-cxx_iostream!
|
76
|
+
bundler (~> 2.0)
|
77
|
+
rake (~> 13.0)
|
78
|
+
rspec (~> 3.0)
|
79
|
+
simplecov (~> 0.10)
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 nejiko96
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# AtCoderFriends::Generator::CxxIostream
|
2
|
+
|
3
|
+
C++(iostream) source generator for [AtCoderFriends](https://github.com/nejiko96/at_coder_friends).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'at_coder_friends-generator-cxx_iostream'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install at_coder_friends-generator-cxx_iostream
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Add ```CxxIostream``` to ```generators``` setting in ```.at_coder_friends.yml```
|
24
|
+
|
25
|
+
## Generator Options
|
26
|
+
|
27
|
+
Following options are available
|
28
|
+
in ```generator_settings/CxxIostream``` section of ```.at_coder_friends.yml```:
|
29
|
+
|
30
|
+
| Option | Description | Default |
|
31
|
+
|---------|-------------|---------|
|
32
|
+
|default_template|Source template file path|[/templates/cxx_iostream.cxx.erb](/templates/cxx_iostream.cxx.erb)|
|
33
|
+
|use_global|if set to true, stores input data in global variables|nil|
|
34
|
+
|
35
|
+
## ```.at_coder_friends.yml``` example
|
36
|
+
```YAML
|
37
|
+
generators:
|
38
|
+
- CxxIoStream
|
39
|
+
generator_settings:
|
40
|
+
CxxIoStream:
|
41
|
+
default_template: /path/to/template
|
42
|
+
use_global: true
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/at_coder_friends-generator-cxx_iostream. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/at_coder_friends-generator-cxx_iostream/blob/master/CODE_OF_CONDUCT.md).
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
59
|
+
|
60
|
+
## Code of Conduct
|
61
|
+
|
62
|
+
Everyone interacting in the AtCoderFriends::Generator::CxxIostream project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/at_coder_friends-generator-cxx_iostream/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/at_coder_friends/generator/cxx_iostream/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'at_coder_friends-generator-cxx_iostream'
|
7
|
+
spec.version = AtCoderFriends::Generator::CxxIostreamConstants::VERSION
|
8
|
+
spec.authors = ['nejiko96']
|
9
|
+
spec.email = ['nejiko2006@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'C++(iostream) generator for AtCoderFriends'
|
12
|
+
spec.description = <<-DESCRIPTION
|
13
|
+
C++(iostream) suorce generator plugin for AtCoderFriends
|
14
|
+
DESCRIPTION
|
15
|
+
spec.homepage = 'https://github.com/nejiko96/at_coder_friends-generator-cxx_iostream'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem
|
20
|
+
# that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
31
|
+
|
32
|
+
spec.metadata = {
|
33
|
+
'homepage_uri' => spec.homepage,
|
34
|
+
'source_code_uri' => spec.homepage,
|
35
|
+
'changelog_uri' => spec.homepage + '/blob/master/CHANGELOG.md'
|
36
|
+
}
|
37
|
+
|
38
|
+
spec.add_dependency 'at_coder_friends', '~> 0.6.6'
|
39
|
+
|
40
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
41
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
43
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
44
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'at_coder_friends/generator/cxx_iostream'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'at_coder_friends'
|
4
|
+
require 'at_coder_friends/generator/cxx_iostream/version'
|
5
|
+
|
6
|
+
module AtCoderFriends
|
7
|
+
module Generator
|
8
|
+
ITEM_TBL = {
|
9
|
+
number: { type: 'int' },
|
10
|
+
decimal: { type: 'double' },
|
11
|
+
string: { type: 'string' },
|
12
|
+
char: { type: 'string', reduce: true }
|
13
|
+
}.tap { |h| h.default = { type: 'int' } }
|
14
|
+
|
15
|
+
# generates C++ constants
|
16
|
+
module CxxIostreamConstGen
|
17
|
+
def gen_const(c)
|
18
|
+
v = cnv_const_value(c.value)
|
19
|
+
if c.type == :max
|
20
|
+
"const int #{c.name.upcase}_MAX = #{v};"
|
21
|
+
else
|
22
|
+
"const int MOD = #{v};"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def cnv_const_value(v)
|
27
|
+
v
|
28
|
+
.sub(/\b10\^/, '1e')
|
29
|
+
.sub(/\b2\^/, '1<<')
|
30
|
+
.gsub(',', "'")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# generates C++ variable declarations
|
35
|
+
module CxxIostreamDeclGen
|
36
|
+
CxxDecl = Struct.new(:type, :name, :initializer) do
|
37
|
+
def format(fnc)
|
38
|
+
case fnc
|
39
|
+
when :decl
|
40
|
+
"#{type} #{name};"
|
41
|
+
when :alloc
|
42
|
+
initializer && "#{name} = #{type}#{initializer};"
|
43
|
+
when :decl_alloc
|
44
|
+
"#{type} #{name}#{initializer};"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def gen_decl(inpdef, fnc)
|
50
|
+
decls =
|
51
|
+
(inpdef.components || [inpdef])
|
52
|
+
.map { |cmp| gen_plain_decl(inpdef, cmp) }
|
53
|
+
decls
|
54
|
+
.push(get_delim_decl(inpdef))
|
55
|
+
.flatten
|
56
|
+
.map { |decl| decl&.format(fnc) }
|
57
|
+
.compact
|
58
|
+
end
|
59
|
+
|
60
|
+
def gen_plain_decl(parent, inpdef)
|
61
|
+
case inpdef.container
|
62
|
+
when :single
|
63
|
+
gen_single_decl(inpdef)
|
64
|
+
when :harray
|
65
|
+
gen_harray_decl(inpdef)
|
66
|
+
when :varray
|
67
|
+
gen_varray_decl(inpdef)
|
68
|
+
when :matrix, :vmatrix, :hmatrix
|
69
|
+
gen_matrix_decl(parent, inpdef)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def gen_single_decl(inpdef)
|
74
|
+
names, cols = inpdef.vars.transpose
|
75
|
+
if cols.uniq.size == 1
|
76
|
+
CxxDecl.new(ITEM_TBL[cols[0]][:type], names.join(', '), nil)
|
77
|
+
else
|
78
|
+
inpdef.vars.map do |name, item|
|
79
|
+
CxxDecl.new(ITEM_TBL[item][:type], name, nil)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def gen_harray_decl(inpdef)
|
85
|
+
type, reduce = ITEM_TBL[inpdef.item].values_at(:type, :reduce)
|
86
|
+
name = inpdef.names[0]
|
87
|
+
sz = inpdef.size[0]
|
88
|
+
if reduce
|
89
|
+
CxxDecl.new(type, name, nil)
|
90
|
+
else
|
91
|
+
CxxDecl.new("vector<#{type}>", name, "(#{sz})")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def gen_varray_decl(inpdef)
|
96
|
+
sz = inpdef.size[0]
|
97
|
+
inpdef.vars.map do |name, item|
|
98
|
+
type = ITEM_TBL[item][:type]
|
99
|
+
CxxDecl.new("vector<#{type}>", name, "(#{sz})")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def gen_matrix_decl(parent, inpdef)
|
104
|
+
sz1, sz2 = inpdef.size
|
105
|
+
inpdef.vars.map do |name, item|
|
106
|
+
type, reduce = ITEM_TBL[item].values_at(:type, :reduce)
|
107
|
+
ctype = reduce ? "vector<#{type}>" : "vector<vector<#{type}>>"
|
108
|
+
initializer = (
|
109
|
+
if reduce
|
110
|
+
"(#{sz1})"
|
111
|
+
elsif parent.container == :varray_matrix # jagged array
|
112
|
+
"(#{sz1})"
|
113
|
+
else
|
114
|
+
"(#{sz1}, vector<#{type}>(#{sz2}))"
|
115
|
+
end
|
116
|
+
)
|
117
|
+
CxxDecl.new(ctype, name, initializer)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_delim_decl(inpdef)
|
122
|
+
return nil if inpdef.delim.empty?
|
123
|
+
|
124
|
+
CxxDecl.new('char', 'delim', nil)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# generates C++(iostream) input source
|
129
|
+
module CxxIostreamInputGen
|
130
|
+
INPUT_FMTS = [
|
131
|
+
['cin >> %<addr>s;', '%<v>s'],
|
132
|
+
['REP(i, %<sz1>s) cin >> %<addr>s;', '%<v>s[i]'],
|
133
|
+
['REP(i, %<sz1>s) REP(j, %<sz2>s) cin >> %<addr>s;', '%<v>s[i][j]']
|
134
|
+
].freeze
|
135
|
+
|
136
|
+
INPUT_FMTS_CMB = {
|
137
|
+
varray_matrix:
|
138
|
+
[
|
139
|
+
[
|
140
|
+
<<~TEXT,
|
141
|
+
REP(i, %<sz1>s) {
|
142
|
+
cin >> %<addr1>s;
|
143
|
+
cin >> %<addr2>s;
|
144
|
+
}
|
145
|
+
TEXT
|
146
|
+
'%<v>s[i]',
|
147
|
+
'%<v>s[i]'
|
148
|
+
],
|
149
|
+
[
|
150
|
+
<<~TEXT,
|
151
|
+
REP(i, %<sz1>s) {
|
152
|
+
cin >> %<addr1>s;
|
153
|
+
%<v2>s[i].resize(%<sz2>s[i]);
|
154
|
+
REP(j, %<sz2>s[i]) cin >> %<addr2>s;
|
155
|
+
}
|
156
|
+
TEXT
|
157
|
+
'%<v>s[i]',
|
158
|
+
'%<v>s[i][j]'
|
159
|
+
]
|
160
|
+
],
|
161
|
+
matrix_varray:
|
162
|
+
[
|
163
|
+
[
|
164
|
+
<<~TEXT,
|
165
|
+
REP(i, %<sz1>s) {
|
166
|
+
cin >> %<addr1>s;
|
167
|
+
cin >> %<addr2>s;
|
168
|
+
}
|
169
|
+
TEXT
|
170
|
+
'%<v>s[i]',
|
171
|
+
'%<v>s[i]'
|
172
|
+
],
|
173
|
+
[
|
174
|
+
<<~TEXT,
|
175
|
+
REP(i, %<sz1>s) {
|
176
|
+
REP(j, %<sz2>s) cin >> %<addr1>s;
|
177
|
+
cin >> %<addr2>s;
|
178
|
+
}
|
179
|
+
TEXT
|
180
|
+
'%<v>s[i][j]',
|
181
|
+
'%<v>s[i]'
|
182
|
+
]
|
183
|
+
]
|
184
|
+
}.tap { |h| h.default = h[:varray_matrix] }
|
185
|
+
|
186
|
+
def gen_input(inpdef)
|
187
|
+
(inpdef.components ? gen_cmb_input(inpdef) : gen_plain_input(inpdef))
|
188
|
+
.split("\n")
|
189
|
+
end
|
190
|
+
|
191
|
+
def gen_plain_input(inpdef)
|
192
|
+
dim = inpdef.size.size
|
193
|
+
dim -= 1 if ITEM_TBL[inpdef.item][:reduce]
|
194
|
+
inp_fmt, addr_fmt = INPUT_FMTS[dim] || INPUT_FMTS[0]
|
195
|
+
sz1, sz2 = inpdef.size
|
196
|
+
addr = edit_addr(inpdef, addr_fmt)
|
197
|
+
format(inp_fmt, sz1: sz1, sz2: sz2, addr: addr)
|
198
|
+
end
|
199
|
+
|
200
|
+
def gen_cmb_input(inpdef)
|
201
|
+
dim = ITEM_TBL[inpdef.item][:reduce] ? 0 : 1
|
202
|
+
inp_fmt, *addr_fmts = INPUT_FMTS_CMB.dig(inpdef.container, dim)
|
203
|
+
sz1, sz2 = inpdef.size
|
204
|
+
addr1, addr2 = inpdef.components.zip(addr_fmts).map do |cmp, addr_fmt|
|
205
|
+
edit_addr(cmp, addr_fmt)
|
206
|
+
end
|
207
|
+
format(
|
208
|
+
inp_fmt,
|
209
|
+
v2: inpdef.names[-1], # jagged array name
|
210
|
+
sz1: sz1,
|
211
|
+
sz2: sz2.split('_')[0],
|
212
|
+
addr1: addr1,
|
213
|
+
addr2: addr2
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
def edit_addr(inpdef, addr_fmt)
|
218
|
+
sep = inpdef.delim.empty? ? ' >> ' : ' >> delim >> '
|
219
|
+
inpdef.names.map { |v| format(addr_fmt, v: v) }.join(sep)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# generates C++(iostream) source from problem description
|
224
|
+
class CxxIostream < Base
|
225
|
+
include CxxIostreamConstants
|
226
|
+
include CxxIostreamConstGen
|
227
|
+
include CxxIostreamDeclGen
|
228
|
+
include CxxIostreamInputGen
|
229
|
+
|
230
|
+
ACF_HOME = File.realpath(File.join(__dir__, '..', '..', '..'))
|
231
|
+
TMPL_DIR = File.join(ACF_HOME, 'templates')
|
232
|
+
DEFAULT_TMPL = File.join(TMPL_DIR, 'cxx_iostream.cxx.erb')
|
233
|
+
ATTRS = Attributes.new(:cxx, DEFAULT_TMPL)
|
234
|
+
|
235
|
+
def attrs
|
236
|
+
ATTRS
|
237
|
+
end
|
238
|
+
|
239
|
+
def gen_consts(constants = pbm.constants)
|
240
|
+
constants.map { |c| gen_const(c) }
|
241
|
+
end
|
242
|
+
|
243
|
+
def gen_global_decls(inpdefs = pbm.formats)
|
244
|
+
fnc = cfg['use_global'] ? :decl : nil
|
245
|
+
inpdefs
|
246
|
+
.map { |inpdef| fnc && gen_decl(inpdef, fnc) || [] }
|
247
|
+
.flatten
|
248
|
+
.compact
|
249
|
+
end
|
250
|
+
|
251
|
+
def gen_local_decls(inpdefs = pbm.formats)
|
252
|
+
fnc = cfg['use_global'] ? :alloc : :decl_alloc
|
253
|
+
inpdefs
|
254
|
+
.map { |inpdef| [gen_decl(inpdef, fnc), gen_input(inpdef)] }
|
255
|
+
.flatten
|
256
|
+
.compact
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
// <%= pbm.url %>
|
2
|
+
|
3
|
+
#define _GLIBCXX_DEBUG
|
4
|
+
#include <bits/stdc++.h>
|
5
|
+
using namespace std;
|
6
|
+
|
7
|
+
<% if pbm.options.interactive -%>
|
8
|
+
#define DEBUG
|
9
|
+
<% end -%>
|
10
|
+
#define REP(i,n) for(int i=0; i<(int)(n); i++)
|
11
|
+
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
|
12
|
+
|
13
|
+
<% if pbm.options.interactive -%>
|
14
|
+
//------------------------------------------------------------------------------
|
15
|
+
#ifdef DEBUG
|
16
|
+
string source;
|
17
|
+
vector<string> responses;
|
18
|
+
#endif
|
19
|
+
|
20
|
+
string query(string req) {
|
21
|
+
cout << "? " << req << endl;
|
22
|
+
string res;
|
23
|
+
#ifdef DEBUG
|
24
|
+
res = "*** generate response from source ***";
|
25
|
+
responses.push_back(res);
|
26
|
+
#else
|
27
|
+
cin >> res;
|
28
|
+
#endif
|
29
|
+
return res;
|
30
|
+
}
|
31
|
+
|
32
|
+
//------------------------------------------------------------------------------
|
33
|
+
<% end -%>
|
34
|
+
<% unless (consts = gen_consts).empty? -%>
|
35
|
+
<% consts.each do |line| -%>
|
36
|
+
<%= line %>
|
37
|
+
<% end -%>
|
38
|
+
|
39
|
+
<% end -%>
|
40
|
+
<% unless (global_decls = gen_global_decls).empty? -%>
|
41
|
+
<% global_decls.each do |line| -%>
|
42
|
+
<%= line %>
|
43
|
+
<% end -%>
|
44
|
+
|
45
|
+
<% end -%>
|
46
|
+
int main() {
|
47
|
+
<% gen_local_decls.each do |line| -%>
|
48
|
+
<%= line %>
|
49
|
+
<% end -%>
|
50
|
+
<% if pbm.options.interactive -%>
|
51
|
+
#ifdef DEBUG
|
52
|
+
cin >> source;
|
53
|
+
#endif
|
54
|
+
<% end -%>
|
55
|
+
|
56
|
+
<% if pbm.options.interactive -%>
|
57
|
+
string ans;
|
58
|
+
cout << "! " << ans << endl;
|
59
|
+
#ifdef DEBUG
|
60
|
+
cout << "query count: " << responses.size() << endl;
|
61
|
+
cout << "query results:" << endl;
|
62
|
+
for (string res : responses) cout << res << endl;
|
63
|
+
#endif
|
64
|
+
<% elsif (vs = pbm.options.binary_values) -%>
|
65
|
+
bool cond = false;
|
66
|
+
cout << (cond ? "<%= vs[0] %>" : "<%= vs[1] %>") << endl;
|
67
|
+
<% else -%>
|
68
|
+
int ans = 0;
|
69
|
+
cout << ans << endl;
|
70
|
+
<% end -%>
|
71
|
+
}
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: at_coder_friends-generator-cxx_iostream
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nejiko96
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: at_coder_friends
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: " C++(iostream) suorce generator plugin for AtCoderFriends\n"
|
84
|
+
email:
|
85
|
+
- nejiko2006@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".rubocop_todo.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CHANGELOG.md
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- at_coder_friends-generator-cxx_iostream.gemspec
|
103
|
+
- bin/console
|
104
|
+
- bin/setup
|
105
|
+
- lib/at_coder_friends/generator/cxx_iostream.rb
|
106
|
+
- lib/at_coder_friends/generator/cxx_iostream/version.rb
|
107
|
+
- templates/cxx_iostream.cxx.erb
|
108
|
+
homepage: https://github.com/nejiko96/at_coder_friends-generator-cxx_iostream
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/nejiko96/at_coder_friends-generator-cxx_iostream
|
113
|
+
source_code_uri: https://github.com/nejiko96/at_coder_friends-generator-cxx_iostream
|
114
|
+
changelog_uri: https://github.com/nejiko96/at_coder_friends-generator-cxx_iostream/blob/master/CHANGELOG.md
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 2.3.0
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.5.2.3
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: C++(iostream) generator for AtCoderFriends
|
135
|
+
test_files: []
|