|
| 1 | +#include "multi_class_design.h" |
1 | 2 | #include "base_validator.h" |
2 | 3 | #include "base_converter.h" |
3 | | -#include <vector> |
4 | | -#include <stdexcept> |
5 | 4 |
|
6 | 5 | namespace multi_class_design { |
7 | 6 |
|
8 | | - std::vector<int> convert_base(const std::vector<int>& digits, int input_base, int output_base) { |
9 | | - // Create validator instance for extensive validation |
10 | | - BaseValidator validator; |
11 | | - |
12 | | - // Perform explicit validation with specific error messages |
13 | | - if (!validator.is_valid_base(input_base)) { |
14 | | - throw std::invalid_argument("Input base must be >= 2"); |
15 | | - } |
16 | | - |
17 | | - if (!validator.is_valid_base(output_base)) { |
18 | | - throw std::invalid_argument("Output base must be >= 2"); |
19 | | - } |
20 | | - |
21 | | - // Check for negative digits specifically |
22 | | - for (int digit : digits) { |
23 | | - if (digit < 0) { |
24 | | - throw std::invalid_argument("Negative digits are not allowed"); |
25 | | - } |
26 | | - } |
27 | | - |
28 | | - // Validate digits for the input base |
29 | | - if (!validator.are_digits_valid_for_base(digits, input_base)) { |
30 | | - throw std::invalid_argument("All digits must be valid for the input base"); |
31 | | - } |
32 | | - |
33 | | - // Handle zero sequence explicitly |
34 | | - if (validator.is_zero_sequence(digits)) { |
35 | | - return {0}; |
36 | | - } |
37 | | - |
38 | | - // Create converter with validator and perform conversion |
39 | | - BaseConverter converter(validator); |
40 | | - return converter.convert(digits, input_base, output_base); |
41 | | - } |
| 7 | +std::vector<int> convert_base(const std::vector<int>& digits, |
| 8 | + int input_base, |
| 9 | + int output_base) { |
| 10 | + // Create validator and converter instances |
| 11 | + BaseValidator validator; |
| 12 | + BaseConverter converter(validator); |
| 13 | + |
| 14 | + // Use the converter to perform the conversion |
| 15 | + // The converter handles all validation and conversion logic |
| 16 | + return converter.convert(digits, input_base, output_base); |
| 17 | +} |
42 | 18 |
|
43 | 19 | } // namespace multi_class_design |
0 commit comments