<commit_before>#ifndef VG_OPTION_HPP_INCLUDED
#define VG_OPTION_HPP_INCLUDED

/**
 * \file option.hpp: Command-line options that can be attached to configurable thing-doer calsses (variant callers, mappers, etc.)
 *
 * To use: make your configurable object inherit from Configurable, and make all your command-line-option fields into Option<whatever type>.
 */

#include <string>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <iostream>
#include <sstream>
#include <getopt.h>
 
namespace vg {

using namespace std;

/**
 * All of the option templates inherit from this base class, which the command-
 * line parser uses to feed them strings.
 */
class OptionInterface {
public:
    /**
     * Get the long oiption text without --, like "foos-to-bar".
     */
    virtual const string& get_long_option() const = 0;
    
    /**
     * Gets a list of short option characters that the option wants, in priority
     * order. If none of these are available, the option will be automatically
     * assigned some other free character.
     */
    virtual const string& get_short_options() const = 0;

    /**
     * Get the description, like "number of foos to bar per frobnitz".
     */
    virtual const string& get_description() const = 0;
    
    /**
     * Get the default value as a string. May be generated on the fly.
     */
    virtual string get_default_value() const = 0;
    
    /**
     * Returns true if the option takes an argument, and false otherwise.
     */
    virtual bool has_argument() const = 0;
    
    /**
     * Called for no-argument options when the parser encounters them.
     */
    virtual void parse() = 0;
    
    /**
     * Called for argument-having options when the parser encounters them. The
     * passed reference is only valid during the function call, so the option
     * should make a copy.
     */
    virtual void parse(const string& arg) = 0;
    
    /**
     * Everyone needs a virtual destructor!
     */
    virtual ~OptionInterface() = default;
};

/**
 * Represents a thing-doing class that has options. You construct the class,
 * configure its options, and then set it going.
 */
class Configurable {
public:
    /**
     * Each option will call this on construction and register with its owner.
     */
    virtual void register_option(OptionInterface* option);
    
    /**
     * Get all the options for this class. These pointers are only valid unless
     * or until the underlying Configurable object moves or is assigned to.
     */
    virtual vector<OptionInterface*> get_options();
    
    /**
     * Get the name of the thing being configured, for titling the help section.
     */
    virtual string get_name();
    
private:
    /// We really should be using something like CRTP and pointer-to-members on
    /// the actual class that's configurable, but for now we'll just exploit
    /// int<->pointer conversion and store the offset from us in memory to the
    /// location of the option in memory. If the option is correctly a mamber of
    /// a class derived from this one, it will work correctly because all
    /// instances share the same memory layout for members.
    vector<ptrdiff_t> option_offsets;
};

/**
 * Actual implementation class that connects a bunch of Configurable things to
 * getopt.
 *
 * TODO: right now every option must have a long option and a char short option.
 * In theory we can use any int as an ID for a long option. We should support
 * long options with untypable or non-char option IDs.
 */
class ConfigurableParser {
public:<commit_msg>Improve option parser docs spelling<commit_after>#ifndef VG_OPTION_HPP_INCLUDED
#define VG_OPTION_HPP_INCLUDED

/**
 * \file option.hpp: Command-line options that can be attached to configurable thing-doer calsses (variant callers, mappers, etc.)
 *
 * To use: make your configurable object inherit from Configurable, and make all your command-line-option fields into Option<whatever type>.
 */

#include <string>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <iostream>
#include <sstream>
#include <getopt.h>
 
namespace vg {

using namespace std;

/**
 * All of the option templates inherit from this base class, which the command-
 * line parser uses to feed them strings.
 */
class OptionInterface {
public:
    /**
     * Get the long option text without --, like "foos-to-bar".
     */
    virtual const string& get_long_option() const = 0;
    
    /**
     * Gets a list of short option characters that the option wants, in priority
     * order. If none of these are available, the option will be automatically
     * assigned some other free character.
     */
    virtual const string& get_short_options() const = 0;

    /**
     * Get the description, like "number of foos to bar per frobnitz".
     */
    virtual const string& get_description() const = 0;
    
    /**
     * Get the default value as a string. May be generated on the fly.
     */
    virtual string get_default_value() const = 0;
    
    /**
     * Returns true if the option takes an argument, and false otherwise.
     */
    virtual bool has_argument() const = 0;
    
    /**
     * Called for no-argument options when the parser encounters them.
     */
    virtual void parse() = 0;
    
    /**
     * Called for argument-having options when the parser encounters them. The
     * passed reference is only valid during the function call, so the option
     * should make a copy.
     */
    virtual void parse(const string& arg) = 0;
    
    /**
     * Everyone needs a virtual destructor!
     */
    virtual ~OptionInterface() = default;
};

/**
 * Represents a thing-doing class that has options. You construct the class,
 * configure its options, and then set it going.
 */
class Configurable {
public:
    /**
     * Each option will call this on construction and register with its owner.
     */
    virtual void register_option(OptionInterface* option);
    
    /**
     * Get all the options for this class. These pointers are only valid unless
     * or until the underlying Configurable object moves or is assigned to.
     */
    virtual vector<OptionInterface*> get_options();
    
    /**
     * Get the name of the thing being configured, for titling the help section.
     */
    virtual string get_name();
    
private:
    /// We really should be using something like CRTP and pointer-to-members on
    /// the actual class that's configurable, but for now we'll just exploit
    /// int<->pointer conversion and store the offset from us in memory to the
    /// location of the option in memory. If the option is correctly a mamber of
    /// a class derived from this one, it will work correctly because all
    /// instances share the same memory layout for members.
    vector<ptrdiff_t> option_offsets;
};

/**
 * Actual implementation class that connects a bunch of Configurable things to
 * getopt.
 *
 * TODO: right now every option must have a long option and a char short option.
 * In theory we can use any int as an ID for a long option. We should support
 * long options with untypeable or non-char option IDs.
 */
class ConfigurableParser {
public:
{'fraction_non_alphanumeric': 0.08124652198107958, 'fraction_numerical': 0.0019476905954368391, 'mean_word_length': 2.8300479488545554, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6386622', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1895, 'n_words': 889}