The Battle for Wesnoth  1.15.0-dev
game_config_manager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2018 by Andrius Silinskas <silinskas.andrius@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #include "game_config_manager.hpp"
15 
16 #include "about.hpp"
17 #include "addon/manager.hpp"
18 #include "ai/configuration.hpp"
19 #include "cursor.hpp"
20 #include "events.hpp"
21 #include "formatter.hpp"
22 #include "game_config.hpp"
23 #include "gettext.hpp"
24 #include "game_classification.hpp"
27 #include "hotkey/hotkey_item.hpp"
29 #include "language.hpp"
30 #include "log.hpp"
31 #include "preferences/general.hpp"
33 #include "terrain/builder.hpp"
34 #include "terrain/type_data.hpp"
35 #include "units/types.hpp"
36 #include "version.hpp"
37 #include "theme.hpp"
38 #include "image.hpp"
39 
40 static lg::log_domain log_config("config");
41 #define ERR_CONFIG LOG_STREAM(err, log_config)
42 #define WRN_CONFIG LOG_STREAM(warn, log_config)
43 #define LOG_CONFIG LOG_STREAM(info, log_config)
44 
46 
48  const commandline_options& cmdline_opts,
49  const bool jump_to_editor) :
50  cmdline_opts_(cmdline_opts),
51  jump_to_editor_(jump_to_editor),
52  game_config_(),
53  old_defines_map_(),
54  paths_manager_(),
55  cache_(game_config::config_cache::instance())
56 {
57  assert(!singleton);
58  singleton = this;
59 
61  cache_.set_use_cache(false);
62  }
65  }
66 }
67 
69 {
70  assert(singleton);
71  singleton = nullptr;
72 }
73 
75  return singleton;
76 }
77 
79 {
80  // Add preproc defines according to the command line arguments.
81  game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
86  game_config::scoped_preproc_define title_screen("TITLE_SCREEN",
88 
91 
93 
96 
97  // Load the standard hotkeys, then apply any player customizations.
100 
104 
105  return true;
106 }
107 
108 namespace {
109 /// returns true if every define in special is also defined in general
110 bool map_includes(const preproc_map& general, const preproc_map& special)
111 {
112  for (const preproc_map::value_type& pair : special)
113  {
114  preproc_map::const_iterator it = general.find(pair.first);
115  if (it == general.end() || it->second != pair.second) {
116  return false;
117  }
118  }
119  return true;
120 }
121 } // end anonymous namespace
122 
125 {
126  game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
128 
129  // Game_config already holds requested config in memory.
130  if (!game_config_.empty()) {
131  if ((force_reload == NO_FORCE_RELOAD) && old_defines_map_ == cache_.get_preproc_map()) {
132  return;
133  }
134  if ((force_reload == NO_INCLUDE_RELOAD) && map_includes(old_defines_map_, cache_.get_preproc_map())) {
135  return;
136  }
137  }
138 
139  gui2::dialogs::loading_screen::display([this, force_reload, classification]() {
140  load_game_config(force_reload, classification);
141  });
142 }
143 
146 {
147  // Make sure that 'debug mode' symbol is set
148  // if command line parameter is selected
149  // also if we're in multiplayer and actual debug mode is disabled.
150 
151  // The loadscreen will erase the titlescreen.
152  // NOTE: even without loadscreen, needed after MP lobby.
153  try {
154  // Read all game configs.
155  // First we load all core configs, the mainline one and the ones from the addons.
156  // Validate the cores and discard the invalid.
157  // Then find the path to the selected core.
158  // Load the selected core.
159  // Handle terrains so that they are last loaded from the core.
160  // Load every compatible addon.
164 
165  // Start transaction so macros are shared.
166  game_config::config_cache_transaction main_transaction;
167 
168  config cores_cfg;
169  // Load mainline cores definition file.
170  cache_.get_config(game_config::path + "/data/cores.cfg", cores_cfg);
171 
172  // Append the $user_campaign_dir/*/cores.cfg files to the cores.
173  std::vector<std::string> user_dirs;
174  {
175  const std::string user_campaign_dir = filesystem::get_addons_dir();
176  std::vector<std::string> user_files;
177  filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs,
179  }
180  for (const std::string& umc : user_dirs) {
181  const std::string cores_file = umc + "/cores.cfg";
182  if (filesystem::file_exists(cores_file)) {
183  config cores;
184  cache_.get_config(cores_file, cores);
185  cores_cfg.append(cores);
186  }
187  }
188 
189  // Validate every core
190  config valid_cores;
191  bool current_core_valid = false;
192  std::string wml_tree_root;
193  for (const config& core : cores_cfg.child_range("core")) {
194 
195  const std::string& id = core["id"];
196  if (id.empty()) {
199  _("Error validating data core."),
200  _("Found a core without id attribute.")
201  + '\n' + _("Skipping the core."));
202  });
203  continue;
204  }
205  if (*&valid_cores.find_child("core", "id", id)) {
208  _("Error validating data core."),
209  _("Core ID: ") + id
210  + '\n' + _("The ID is already in use.")
211  + '\n' + _("Skipping the core."));
212  });
213  continue;
214  }
215 
216  const std::string& path = core["path"];
220  _("Error validating data core."),
221  _("Core ID: ") + id
222  + '\n' + _("Core Path: ") + path
223  + '\n' + _("File not found.")
224  + '\n' + _("Skipping the core."));
225  });
226  continue;
227  }
228 
229  if (id == "default" && !current_core_valid) {
230  wml_tree_root = path;
231  }
232  if (id == preferences::core_id()) {
233  current_core_valid = true;
234  wml_tree_root = path;
235  }
236 
237  valid_cores.add_child("core", core); // append(core);
238  }
239 
240  if (!current_core_valid) {
243  _("Error loading core data."),
244  _("Core ID: ") + preferences::core_id()
245  + '\n' + _("Error loading the core with named id.")
246  + '\n' + _("Falling back to the default core."));
247  });
248  preferences::set_core_id("default");
249  }
250 
251  // check if we have a valid default core which should always be the case.
252  if (wml_tree_root.empty()) {
255  _("Error loading core data."),
256  _("Can't locate the default core.")
257  + '\n' + _("The game will now exit."));
258  });
259  throw;
260  }
261 
262  // Load the selected core
264  game_config_.append(valid_cores);
265 
266  main_transaction.lock();
267 
268  // Put the gfx rules aside so that we can prepend the add-on
269  // rules to them.
270  config core_terrain_rules;
271  core_terrain_rules.splice_children(game_config_, "terrain_graphics");
272 
274  load_addons_cfg();
275 
276  // If multiplayer campaign is being loaded, [scenario] tags should
277  // become [multiplayer] tags and campaign's id should be added to them
278  // to allow to recognize which scenarios belongs to a loaded campaign.
279  if (classification != nullptr) {
280  if (const config& campaign = game_config().find_child("campaign", "id", classification->campaign))
281  {
282  const bool require_campaign = campaign["require_campaign"].to_bool(true);
283  for (config& scenario : game_config_.child_range("scenario"))
284  {
285  scenario["require_scenario"] = require_campaign;
286  }
287  }
288  }
289 
290  // Extract the Lua scripts at toplevel.
293 
294  // Put the gfx rules back to game config.
295  game_config_.splice_children(core_terrain_rules, "terrain_graphics");
296 
298  set_unit_data();
300 
302  tdata_ = std::make_shared<terrain_type_data>(game_config_);
305  } catch(const game::error& e) {
306  ERR_CONFIG << "Error loading game configuration files\n" << e.message << '\n';
307 
308  // Try reloading without add-ons
309  if (!game_config::no_addons) {
310  game_config::no_addons = true;
313  _("Error loading custom game configuration files. The game will try without loading add-ons."),
314  e.message);
315  });
316  load_game_config(force_reload, classification);
317  } else if (preferences::core_id() != "default") {
320  _("Error loading custom game configuration files. The game will fallback to the default core files."),
321  e.message);
322  });
323  preferences::set_core_id("default");
324  game_config::no_addons = false;
325  load_game_config(force_reload, classification);
326  } else {
329  _("Error loading default core game configuration files. The game will now exit."),
330  e.message);
331  });
332  throw;
333  }
334  }
335 
337 
338  // Set new binary paths.
340 }
341 
343 {
344  const std::string user_campaign_dir = filesystem::get_addons_dir();
345 
346  std::vector<std::string> error_log;
347  std::vector<std::string> error_addons;
348  std::vector<std::string> user_dirs;
349  std::vector<std::string> user_files;
350 
351  filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs,
353 
354  // Warn player about addons using the no-longer-supported single-file format.
355  for(const std::string& file : user_files) {
356  const int size_minus_extension = file.size() - 4;
357 
358  if(file.substr(size_minus_extension, file.size()) == ".cfg") {
359  ERR_CONFIG << "error reading usermade add-on '" << file << "'\n";
360 
361  error_addons.push_back(file);
362 
363  const int userdata_loc = file.find("data/add-ons") + 5;
364  const std::string log_msg = formatter()
365  << "The format '~"
366  << file.substr(userdata_loc)
367  << "' (for single-file add-ons) is not supported anymore, use '~"
368  << file.substr(userdata_loc, size_minus_extension - userdata_loc)
369  << "/_main.cfg' instead.";
370 
371  error_log.push_back(log_msg);
372  }
373  }
374 
375  // Rerun the directory scan using filename only, to get the addon_ids more easily.
376  user_files.clear();
377  user_dirs.clear();
378 
379  filesystem::get_files_in_dir(user_campaign_dir, nullptr, &user_dirs,
381 
382  // Load the addons.
383  for(const std::string& addon_id : user_dirs) {
384  const std::string addon_dir = user_campaign_dir + "/" + addon_id;
385 
386  const std::string main_cfg = addon_dir + "/_main.cfg";
387  const std::string info_cfg = addon_dir + "/_info.cfg";
388 
389  if(!filesystem::file_exists(main_cfg)) {
390  continue;
391  }
392 
393  // Try to find this addon's metadata. Author publishing info (_server.pbl) is given
394  // precedence over addon sever-generated info (_info.cfg). If neither are found, it
395  // probably means the addon was installed manually and certain defaults will be used.
396  config metadata;
397 
398  if(have_addon_pbl_info(addon_id)) {
399  // Publishing info needs to be read from disk.
400  metadata = get_addon_pbl_info(addon_id);
401  } else if(filesystem::file_exists(info_cfg)) {
402  // Addon server-generated info can be fetched from cache.
403  config temp;
404  cache_.get_config(info_cfg, temp);
405 
406  metadata = temp.child_or_empty("info");
407  }
408 
409  std::string using_core = metadata["core"];
410  if(using_core.empty()) {
411  using_core = "default";
412  }
413 
414  // Skip add-ons not matching our current core. Cores themselves should be selectable
415  // at all times, so they aren't considered here.
416  if(!metadata.empty() && metadata["type"] != "core" && using_core != preferences::core_id()) {
417  continue;
418  }
419 
420  std::string addon_title = metadata["title"].str();
421  if(addon_title.empty()) {
422  addon_title = addon_id;
423  }
424 
425  version_info addon_version(metadata["version"]);
426 
427  try {
428  // Load this addon from the cache to a config.
429  config umc_cfg;
430  cache_.get_config(main_cfg, umc_cfg);
431 
432  static const std::set<std::string> tags_with_addon_id {
433  "era",
434  "modification",
435  "resource",
436  "multiplayer",
437  "scenario",
438  "campaign"
439  };
440 
441  // Annotate appropriate addon types with addon_id info.
442  for(auto child : umc_cfg.all_children_range()) {
443  if(tags_with_addon_id.count(child.key) > 0) {
444  auto& cfg = child.cfg;
445  cfg["addon_id"] = addon_id;
446  cfg["addon_title"] = addon_title;
447  // Note that this may reformat the string in a canonical form.
448  cfg["addon_version"] = addon_version.str();
449  }
450  }
451 
452  game_config_.append(std::move(umc_cfg));
453  } catch(const config::error& err) {
454  ERR_CONFIG << "error reading usermade add-on '" << main_cfg << "'" << std::endl;
455  ERR_CONFIG << err.message << '\n';
456  error_addons.push_back(main_cfg);
457  error_log.push_back(err.message);
458  } catch(const preproc_config::error& err) {
459  ERR_CONFIG << "error reading usermade add-on '" << main_cfg << "'" << std::endl;
460  ERR_CONFIG << err.message << '\n';
461  error_addons.push_back(main_cfg);
462  error_log.push_back(err.message);
463  } catch(const filesystem::io_exception&) {
464  ERR_CONFIG << "error reading usermade add-on '" << main_cfg << "'" << std::endl;
465  error_addons.push_back(main_cfg);
466  }
467  }
468 
469  if(!error_addons.empty()) {
470  const std::size_t n = error_addons.size();
471  const std::string& msg1 =
472  _n("The following add-on had errors and could not be loaded:",
473  "The following add-ons had errors and could not be loaded:",
474  n);
475  const std::string& msg2 =
476  _n("Please report this to the author or maintainer of this add-on.",
477  "Please report this to the respective authors or maintainers of these add-ons.",
478  n);
479 
480  const std::string& report = utils::join(error_log, "\n\n");
482  gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report);
483  });
484  }
485 }
486 
488 {
489  config& hashes = game_config_.add_child("multiplayer_hashes");
490  for (const config &ch : game_config_.child_range("multiplayer")) {
491  hashes[ch["id"].str()] = ch.hash();
492  }
493 }
494 
496 {
497  game_config_.merge_children("units");
499  if(config &units = game_config_.child("units")) {
500  unit_types.set_config(units);
501  }
502 }
503 
505 {
506  // Rebuild addon version info cache.
508 
509  // Force a reload of configuration information.
511  old_defines_map_.clear();
514 
516 }
517 
519 {
522 }
523 
526 {
527  game_config::scoped_preproc_define difficulty(classification.difficulty,
528  !classification.difficulty.empty());
529  game_config::scoped_preproc_define campaign(classification.campaign_define,
530  !classification.campaign_define.empty());
531  game_config::scoped_preproc_define scenario(classification.scenario_define,
532  !classification.scenario_define.empty());
534  !classification.era_define.empty());
535  game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
536  classification.campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
538  classification.campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
539 
540  //
541  // NOTE: these deques aren't used here, but the objects within are utilized as RAII helpers.
542  //
543 
544  typedef std::unique_ptr<game_config::scoped_preproc_define> define;
545 
546  std::deque<define> extra_defines;
547  for(const std::string& extra_define : classification.campaign_xtra_defines) {
548  extra_defines.emplace_back(new game_config::scoped_preproc_define(extra_define));
549  }
550 
551  std::deque<define> modification_defines;
552  for(const std::string& mod_define : classification.mod_defines) {
553  modification_defines.emplace_back(new game_config::scoped_preproc_define(mod_define, !mod_define.empty()));
554  }
555 
556  try {
558  } catch(const game::error&) {
560 
561  std::deque<define> previous_defines;
562  for(const preproc_map::value_type& preproc : old_defines_map_) {
563  previous_defines.emplace_back(new game_config::scoped_preproc_define(preproc.first));
564  }
565 
567 
568  throw;
569  }
570 
571  // This needs to be done in the main thread since this function (load_game_config_for_game)
572  // might be called from a loading screen worker thread (and currently is, in fact). If the
573  // image cache is purged from the worker thread, there's a possibility for a data race where
574  // the main thread accesses the image cache and the worker thread simultaneously clears it.
576 }
577 
579 {
580  game_config::scoped_preproc_define multiplayer("MULTIPLAYER", is_mp);
581  game_config::scoped_preproc_define test("TEST", is_test);
582  game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest && is_mp);
583 ///During an mp game the default difficuly define is also defined so better already load it now if we alreeady must reload config cache.
585 
586  typedef std::unique_ptr<game_config::scoped_preproc_define> define;
587  try{
589  }
590  catch(const game::error&) {
592 
593  std::deque<define> previous_defines;
594  for (const preproc_map::value_type& preproc : old_defines_map_) {
595  previous_defines.emplace_back(new game_config::scoped_preproc_define(preproc.first));
596  }
597 
599 
600  throw;
601  }
602 }
void set_config(config &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1103
Don&#39;t reload if the previous defines include the new defines.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:423
bool mptest
True if –mp-test was given on the command line.
const_all_children_itors all_children_range() const
In-order iteration over all children.
Definition: config.cpp:874
void set_paths(const config &cfg)
void clear_children(T... keys)
Definition: config.hpp:477
std::string era()
Definition: game.cpp:696
game_classification * classification
Definition: resources.cpp:34
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:291
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
config & find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Definition: config.cpp:789
static void set_known_themes(const config *cfg)
Definition: theme.cpp:875
static bool file_exists(const fs::path &fpath)
Definition: filesystem.cpp:300
void merge_children(const std::string &key)
All children with the given key will be merged into the first element with that key.
Definition: config.cpp:329
bool noaddons
True if –noaddons was given on the command line. Disables the loading of all add-ons.
void lock()
Lock the transaction so no more macros are added.
void set_scope_active(scope s, bool set)
child_itors child_range(config_key_type key)
Definition: config.cpp:366
filesystem::binary_paths_manager paths_manager_
static void progress(loading_stage stage=loading_stage::none)
const std::string DEFAULT_DIFFICULTY
The default difficulty setting for campaigns.
#define ERR_CONFIG
unit_type_data unit_types
Definition: types.cpp:1442
Don&#39;t reload if the previous defines equal the new defines.
static lg::log_domain log_config("config")
void load_config(const config &v)
static void add_color_info(const config &v, bool build_defaults)
Used to set and unset scoped defines to preproc_map.
void call_in_main_thread(const std::function< void(void)> &f)
Definition: events.cpp:723
void flush_cache()
Definition: image.cpp:244
void clear_binary_paths_cache()
static void extract_preload_scripts(const config &game_config)
static game_config_manager * get()
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
Definition: config.cpp:579
void load_hotkeys()
Definition: general.cpp:857
std::ostringstream wrapper.
Definition: formatter.hpp:38
std::string campaign_define
If there is a define the campaign uses to customize data.
void get_config(const std::string &path, config &cfg)
Gets a config object from given path.
static UNUSEDNOWARN std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:93
void set_force_valid_cache(bool force)
Enable/disable cache validation.
void set_core_id(const std::string &core_id)
Definition: general.cpp:321
static game_config_manager * singleton
std::string path
Definition: game_config.cpp:39
boost::optional< std::string > test
Non-empty if –test was given on the command line. Goes directly into test mode, into a scenario...
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:303
bool multiplayer
True if –multiplayer was given on the command line. Goes directly into multiplayer mode...
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on&#39;s version information structs.
Definition: manager.cpp:282
std::string campaign
The id of the campaign being played.
void deactivate_all_scopes()
log_domain & general()
Definition: log.cpp:104
config get_addon_pbl_info(const std::string &addon_name)
Gets the publish information for an add-on.
Definition: manager.cpp:78
std::string era_define
If there is a define the era uses to customize data.
void set_use_cache(bool use)
Enable/disable caching.
void clear_defines()
Clear stored defines map to default values.
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, file_name_option mode, file_filter_option filter, file_reorder_option reorder, file_tree_checksum *checksum)
Populates &#39;files&#39; with all the files and &#39;dirs&#39; with all the directories in dir.
Definition: filesystem.cpp:386
game_config_manager(const commandline_options &cmdline_opts, const bool jump_to_editor)
bool nocache
True if –nocache was given on the command line. Disables cache usage.
logger & err()
Definition: log.cpp:78
std::vector< std::string > campaign_xtra_defines
more customization of data
std::string get_wml_location(const std::string &filename, const std::string &current_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn&#39;t pres...
bool have_addon_pbl_info(const std::string &addon_name)
Returns true if there&#39;s a local .pbl file stored for the specified add-on.
Definition: manager.cpp:73
void load_game_config_for_create(bool is_mp, bool is_test=false)
Game configuration data as global variables.
Definition: build_info.cpp:46
const preproc_map & get_preproc_map() const
An exception object used when an IO error occurs.
Definition: filesystem.hpp:48
void reset_color_info()
std::string scenario_define
If there is a define the scenario uses to customize data.
std::vector< std::string > mod_defines
If there are defines the modifications use to customize data.
Definitions related to theme-support.
const bool & debug
Definitions for the terrain builder.
static void display(const std::string &summary, const std::string &post_summary, const std::vector< std::string > &files, const std::string &details)
The display function; see modal_dialog for more information.
Definition: wml_error.hpp:43
Represents version numbers.
Definition: version.hpp:43
config & add_child(config_key_type key)
Definition: config.cpp:479
const file_tree_checksum & data_tree_checksum(bool reset=false)
Get the time at which the data/ tree was last modified at.
std::string difficulty
The difficulty level the game is being played on.
std::string core_id()
Definition: general.cpp:315
void set_about(const config &cfg)
Regenerates the credits config.
Definition: about.cpp:106
Used to share macros between cache objects You have to create transaction object to load all macros t...
static void display(std::function< void()> f)
void load_game_config_for_game(const game_classification &classification)
static void set_terrain_rules_cfg(const config &cfg)
Set the config where we will parse the global terrain rules.
Definition: builder.cpp:290
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
void load_hotkeys(const config &cfg, bool set_as_default)
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey lis...
std::string get_addons_dir()
Managing the AIs configuration - headers.
Standard logging facilities (interface).
std::string str() const
Serializes the version number into string form.
Definition: version.cpp:115
std::string message
Definition: exceptions.hpp:31
const commandline_options & cmdline_opts_
bool validcache
True if –validcache was given on the command line. Makes Wesnoth assume the cache is valid...
bool init_strings(const config &cfg)
Initializes certain English strings.
Definition: language.cpp:326
game_config::config_cache & cache_
std::map< std::string, struct preproc_define > preproc_map
#define e
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
Definition: config.cpp:456
static void init(const config &game_config)
Init the parameters of ai configuration parser.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
Interfaces for manipulating version numbers of engine, add-ons, etc.
static map_location::DIRECTION n
bool init_game_config(FORCE_RELOAD_CONFIG force_reload)
std::string hash() const
Definition: config.cpp:1275
std::string path
File path.
bool empty() const
Definition: config.cpp:837
const config & game_config() const
void load_game_config(FORCE_RELOAD_CONFIG force_reload, game_classification const *classification=nullptr)
void recheck_filetree_checksum()
Force cache checksum validation.
void load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG force_reload, game_classification const *classification=nullptr)