|
| 1 | +# C++ Programmer's Test Task |
| 2 | + |
| 3 | +It is necessary to write a class in pure C++ that can read huge text log files |
| 4 | +(hundreds of megabytes, tens of gigabytes) as quickly as possible and produce lines |
| 5 | +that satisfy the conditions of the simplest regexp: (at least the `*` and `?` operators, |
| 6 | +a wider range of possibilities are welcome): |
| 7 | + |
| 8 | +- character `*` - sequence of any characters of unlimited length; |
| 9 | +- character `?` - any one character; |
| 10 | +- masks should be processed correctly: `*Some*`, `*Some`, `Some*`, `*****Some***` - |
| 11 | + there are no restrictions on the position `*` in the mask. |
| 12 | + |
| 13 | +The search result must be strings that match the mask. |
| 14 | + |
| 15 | +For example: |
| 16 | + |
| 17 | +- The mask `*abc*` selects all lines containing `abc` and starting and ending with any sequence of characters. |
| 18 | +- The `abc*` mask matches all strings starting with `abc` and ending with any sequence of characters. |
| 19 | +- The `abc?` mask selects all lines starting with `abc` and ending with any additional character. |
| 20 | +- The `abc` mask selects all strings that are equal to this mask. |
| 21 | + |
| 22 | +The class will not be extended and will not be a base class. |
| 23 | + |
| 24 | +Character encoding: all files and regex patterns are ANSI (non-unicode single-byte encoding). |
| 25 | + |
| 26 | +The class must have the following public interface: |
| 27 | + |
| 28 | +```cpp |
| 29 | +class CLogReader |
| 30 | + { |
| 31 | +public: |
| 32 | + CLogReader(...); |
| 33 | + ~CLogReader(...); |
| 34 | + |
| 35 | + bool Open(...); // opening a file, false - error |
| 36 | + void Close(); // close the file |
| 37 | + |
| 38 | + bool SetFilter(const char *filter); // setting the line filter, false - error |
| 39 | + bool GetNextLine(char *buf, // request for the next matched line, |
| 40 | + const int bufsize); // buf - buffer, bufsize - maximum length |
| 41 | + // false - end of file or error |
| 42 | + }; |
| 43 | +``` |
| 44 | +
|
| 45 | +## Implementation Requirements |
| 46 | +
|
| 47 | +- Platform: Windows 7 and above |
| 48 | +- Functionality: maximum performance (caching of search results and file is not required) |
| 49 | +- Resources: memory costs should be minimal (within reasonable limits) |
| 50 | +- Components: use of third-party libraries (including STL) and components is prohibited. |
| 51 | + Only WinAPI and CRT are allowed. |
| 52 | +- Exceptions: Windows and C++ exceptions cannot be used |
| 53 | +- The code must be absolutely "indestructible" and protected from errors |
| 54 | +
|
| 55 | +## Design Requirements |
| 56 | +
|
| 57 | +- The code should be as simple as possible |
| 58 | +- The code should be as clean, beautiful and understandable as possible |
| 59 | +- The result should be a finished class (`.cpp` + `.h` files) and a console example app |
| 60 | + which opens a text file of a couple of megabytes and greps `order*closed`. |
| 61 | +- The console example app should receive the path to the text file (the first parameter) |
| 62 | + and the line filter(the second parameter) as command line parameters and output |
| 63 | + the found lines in full to the console. Run line example: |
| 64 | + `tool.exe 20190102.log *bbb*` |
| 65 | +- The project must be designed for building in MS Visual Studio 2015 and higher. |
| 66 | +
|
| 67 | +Any comments in the code are welcome! `:)` |
| 68 | +
|
| 69 | +--- |
0 commit comments