Skip to content

Everything is configurable (for 1.x)

Shiva Wu edited this page Nov 14, 2013 · 1 revision

In Greed, what you can change

  • Where would greed save and find your code
  • How greed manage your code folder structure, according to the contest and problem related
  • Source code name, including filename and extension
  • Source code and test code template, where a template engine is used to give full control of what's produced

Config Library

A Config Library is used, to enable advanced features configurable by good-structured and readable config file.

You may think: What? I need to learn a whole new configuration format? That's crap!

Well, you don't have to. Just follow my lead. No new stuff, it's easy, trust me!

In case you do want to learn more, read the full specification of the HOCON.

Config Manual

How to write config file

The configuration file consists of some key-value pairs. You can use the following 3 identical ways to define the key-value pairs.

greed.templates.pathPattern = value
greed {
  templates.pathPattern = value
}
greed {
  templates {
    pathPattern = value
    anotherKey = "another value" # you can add multiple key-value pairs here
  }
}

The values must be quoted by "", if they contain special characters like :, #, $, and so on. You can also use "${var}" to refer to some predefined variables when setting the values (see below for a partial list of available predefined variables). Those predefined variables will be resolved by our template engine, which is described in the Templates page. You should pay attention to the double quotation marks "" here since omitting it will result in something called cross-reference, which is seldom used in the situation.

That's all you need to know about writing config! So easy!

.conf file

There's a default.conf bundled with the Greed package, which is used as the default config. All keys are written in this file, and you can start working without changing anything.

But, if you want to DIY, no problem! Just put a greed.conf in the root of your workspace. Your settings in this file will override those in default.conf.

Available Setting Key-Value Pairs

The following key-pair values are available to override. In which <lang> represents a programming language and would be replaced by an actual value. Currently supported values are cpp, java, csharp, python and vb. The default values shown below is for cpp language.

Key Path Default Value Comment
greed.codeRoot . . points to the root of your workspace
greed.override false true will backup your current code if exists(10 versions kept), false means not overriding existing file
greed.logLevel OFF log levels are DEBUG, INFO, WARN, ERROR, and you can set it to ALL or OFF
greed.logToStderr true if true, logs will be printed on System.err also
greed.templates.pathPattern "${Contest.Name}" Specify your working directory for the current contest and problem, e.g. the default value will generate to and fetch from directories like SRM 257 in your codeRoot
greed.templates.fileNamePattern "${Problem.Name}" Specify the generated source code file name, pay attention to the "" here and above, which prevents ${} to be resolved by the config itself
greed.templates.<lang>.extension cpp And the extension for the source code according to your programming language
greed.templates.<lang>.tmplFile "res:/Template.cpp" code template file for language, res: refers to resource inside the Greed package, otherwise the resource is located in your workspace
greed.templates.<lang>.testTmplFile "res:/GreedTest.cpp" test code template for language, which will be binded to <TestCode> tag in your code template
greed.templates.<lang>.cutBegin "// CUT begin" the beginning notation of your cutting block
greed.templates.<lang>.cutEnd "// CUT end" the end
greed.templates.cpp.spec.longIntTypeName "long long" The type name to use for 64 bit integers in c++.
greed.test.recordRuntime true whether to record runtime in your test code, refer to the Templates page for details
greed.test.recordScore true whether to record problem score in your test code. If you don't like it, turn it off.

Available Predefined Variables

You may see some "${}" notation above, that's predefined variables for you to customize your settings. A list of predefined variables you may find useful in setting the configurations here is shown below. You may refer to Templates page for all available predefined variables.

Value Name Example
Contest.Name SRM 257
Contest.Div 1
Problem.Name RabbitWorking
Problem.Score 1000