Logo Search packages:      
Sourcecode: gaffitter version File versions  Download package

bool Params::Initialize (  ) 

Set gaffitter options from user args.

Definition at line 158 of file Params.cc.

References OptionsINT::Add(), OptionsFLOAT::Add(), OptionsType< T >::Add(), CmdLineParser::Bool, CmdLineParser::Char, CmdLineParser::Float, OptionsType< T >::Found(), OptionsType< T >::Get(), CmdLineParser::Int, m_approximate, m_block_size, m_brute_force, m_cmdline_items, m_delimit_chr, m_di_factor, m_direct_input, m_enclose, m_enclose_chr, m_factor, m_ga_cross_prob, m_ga_mut_prob, m_ga_num_gens, m_ga_pop_size, m_ga_seed, m_ga_sel_pressure, m_hide_selected, m_hide_summary, m_iterations, m_max_size, m_no_case, m_no_metric, m_pipe, m_show_bytes, m_show_size, m_show_unselected, m_sort_by_size, m_sort_reverse, m_split, m_target, m_unit_power, m_unit_symbol, m_verbose, CmdLineParser::Process(), ShowUsage(), and ShowVersion().

{
   CmdLineParser Opts(m_argc,m_argv,m_cmdline_items);

   Opts.Bool.Add("-h","--help");
   Opts.Bool.Add("--version");

   Opts.Bool.Add("-");

   Opts.Bool.Add("--si");

   Opts.Bool.Add("-b","--bytes");
   Opts.Bool.Add("-k","--kb");
   Opts.Bool.Add("-m","--mb");
   Opts.Bool.Add("-g","--gb");

   Opts.Bool.Add("--di","--direct-input");
   Opts.Bool.Add("--di-b","--di-bytes");
   Opts.Bool.Add("--di-k","--di-kb");
   Opts.Bool.Add("--di-m","--di-mb");
   Opts.Bool.Add("--di-g","--di-gb");
   Opts.Bool.Add("--di-si");

   Opts.Float.Add("-t","--target",-1.0,0.0,numeric_limits<Size_t>::max());

   Opts.Int.Add("-i","--iter",1,1,numeric_limits<int>::max());
   Opts.Bool.Add("-i","--iter");

   Opts.Float.Add("--min","--min-size",0.0,0.0,numeric_limits<Size_t>::max());
   Opts.Float.Add("--max","--max-size",numeric_limits<Size_t>::max(),0.0,
                                       numeric_limits<Size_t>::max());

   Opts.Int.Add("--bs","--block-size",1,1,numeric_limits<int>::max());

   Opts.Bool.Add("-v","--verbose");

   Opts.Bool.Add("--hs","--hide-summary");
   Opts.Bool.Add("--ss","--show-size");
   Opts.Bool.Add("--sb","--show-bytes");
   Opts.Bool.Add("--su","--show-unselected");
   Opts.Bool.Add("--hsel","--hide-selected");

   Opts.Bool.Add("-s","--sort-by-size");
   Opts.Bool.Add("-r","--sort-reverse");
   Opts.Bool.Add("-n","--no-case");

   Opts.Int.Add("--ga-ng","--ga-num-generations",0,0,numeric_limits<int>::max());
   Opts.Int.Add("--ga-ps","--ga-pop-size",0,0,numeric_limits<int>::max());
   Opts.Float.Add("--ga-cp","--ga-cross-prob",0.95,0.0,1.0);
   Opts.Float.Add("--ga-mp","--ga-mutation-prob",-1.0,0.0,1.0);
   Opts.Int.Add("--ga-sp","--ga-sel-pressure",0,0,numeric_limits<int>::max());
   Opts.Bool.Add("--ga-rs","--ga-random-seed");
   Opts.Int.Add("--ga-s","--ga-seed",1,0,numeric_limits<long>::max());

   Opts.Bool.Add("--bf","--brute-force");
   Opts.Bool.Add("--ap","--approximate");
   Opts.Bool.Add("--sp","--split");

   Opts.Char.Add("--dw","--delimit-with",'\n');
   Opts.Char.Add("--ew","--enclose-with",'\0');

   // -- Get the options! ----------------
   Opts.Process();
   // ------------------------------------

   if (Opts.Bool.Get("-h")) { ShowUsage(); return false; /* exit */ }
   if (Opts.Bool.Get("--version")) { ShowVersion(); return false; /* exit */ }

   m_pipe = Opts.Bool.Get("-");

   // ---- units
   if (Opts.Bool.Get("--si"))
   {
      m_unit_symbol='\0';
      m_unit_power=1000.0;
   }
   else
   {
      m_unit_symbol='i';
      m_unit_power=1024.0;
   }

   if (Opts.Bool.Get("-b")) m_factor = 1.0;
   else if (Opts.Bool.Get("-k")) m_factor = KB();
   else if (Opts.Bool.Get("-m")) m_factor = MB();
   else if (Opts.Bool.Get("-g")) m_factor = GB();
   else m_factor = MB(); // default to MiB (mebibyte)

   // --- manual input (no files)
   m_direct_input = Opts.Bool.Get("--di");

   if (m_direct_input)
   {
      double di_power = Opts.Bool.Get("--di-si") ? 1000.0 : 1024.0;

      if (Opts.Bool.Get("--di-b")) m_di_factor = 1.0;
      else if (Opts.Bool.Get("--di-k")) m_di_factor = KB(di_power);
      else if (Opts.Bool.Get("--di-m")) m_di_factor = MB(di_power);
      else if (Opts.Bool.Get("--di-g")) m_di_factor = GB(di_power);
      else m_no_metric = true; // default to no metric!
   }

   // ---- Target size (default = none) [mandatory option]
   m_target = Opts.Float.Get<Size_t>("-t");
   if (m_target <= 0.0) throw E_NoTarget(); 

   // adjust power of m_target if necessary (when no_metric is unset)
   if (!m_no_metric) m_target = floor(m_target * m_factor);

   // ---- Iterations (default = 1)
   if (Opts.Int.Found("-i")) m_iterations = Opts.Int.Get("-i");
   else if (Opts.Bool.Get("-i")) 
           m_iterations = numeric_limits<int>::max(); // "infinite"

   // --- min and max file size
   m_min_size = Opts.Float.Get<Size_t>("--min");

   // check range and if m_factor must be applicated
   if (m_min_size > 0.0 && !m_no_metric) m_min_size = ceil(m_min_size * m_factor);

   m_max_size = Opts.Float.Get<Size_t>("--max");

   // check range and if m_factor must be applicated
   if (m_max_size <= 0.0) m_max_size = numeric_limits<Size_t>::max();
   else if (!m_no_metric) m_max_size = floor(m_max_size * m_factor);

   // --- block size
   m_block_size = Opts.Int.Get("--bs");

   // --- verbose
   m_verbose = Opts.Bool.Get("-v");

   // --- hide summary (last line)?
   m_hide_summary = Opts.Bool.Get("--hs");
   
   // --- show sizes?
   m_show_size = Opts.Bool.Get("--ss");
   
   // --- show bytes?
   // showing bytes in direct input mode (with no metric) make no sense.
   m_show_bytes = Opts.Bool.Get("--sb") && !m_no_metric;

   // --- show unselected files?
   m_show_unselected = Opts.Bool.Get("--su");

   // --- hide selected files?
   m_hide_selected = Opts.Bool.Get("--hsel");

   // --- sort by size?
   m_sort_by_size = Opts.Bool.Get("-s");

   // --- reverse order while sorting?
   m_sort_reverse = Opts.Bool.Get("-r");

   // --- case-sensitive or insensitive? (only for "sort by name")
   m_no_case = Opts.Bool.Get("-n");

   // ---- Genetic Algorithm ------------------------------------------
   /* m_ga_pop_size and m_ga_num_gens are (auto)adjusted in
    * Optimizer::Initialize */

   // -- Number of generations
   m_ga_num_gens = Opts.Int.Get("--ga-ng"); // check range: done in 
                                            // Optimizer::Initialize
   // -- Population size
   m_ga_pop_size = Opts.Int.Get("--ga-ps"); // check range: done in 
                                            // Optimizer::Initialize

   // -- Crossover probability
   m_ga_cross_prob = Opts.Float.Get("--ga-cp");

   // -- Mutation probability
   m_ga_mut_prob = Opts.Float.Get("--ga-mp"); // automatic value adjusted 
                                              // by GeneticAlgorithm (~1/L)

   // -- Selection pressure (currently "tournament size")
   m_ga_sel_pressure = Opts.Int.Get("--ga-sp"); // check range: done in 
                                                // Optimizer::Initialize

   // -- Initialization seed
   if (Opts.Bool.Get("--ga-rs")) m_ga_seed = 0;
   else m_ga_seed = Opts.Int.Get("--ga-s");

   // ---- Search ----------------------------------------------
   // --- Brute Force Search. May be very slow ( O(2^|input|) )
   m_brute_force = Opts.Bool.Get("--bf");

   // --- Best First Search (very fast but just approximate)
   m_approximate = Opts.Bool.Get("--ap");

   // --- Split "Search"
   m_split = Opts.Bool.Get("--sp");

   // --------------------

   // Separate and Enclose options
   m_delimit_chr = Opts.Char.Get("--dw"); // default = "\n" (new line)
   m_enclose_chr = Opts.Char.Get("--ew"); // default = none (no enclose char)
   m_enclose = Opts.Char.Found("--ew"); // C++ hasn't a truly empty char (not '\0')

   // ---------------
   return true;
}


Generated by  Doxygen 1.6.0   Back to index