diff --git a/documents/references.md b/documents/references.md index f123376042fd188949bfbdd10a355e075dd58114..98763cc1f36fccc4509f4d95b78e9c5a0d1afdef 100644 --- a/documents/references.md +++ b/documents/references.md @@ -5,34 +5,46 @@ Various references used in project. -## References +## C++ References -### C++ References - -#### Book Reference +### Book Reference "A Tour of C++", by Bjarne Stroustrup -#### File Compiling without "Standard" C++ Library -<https://stackoverflow.com/a/10271117> - +### File and Directory Handling #### Checking if File Path Exists <https://stackoverflow.com/a/27588225> #### Checking if Path is File or Dir <https://stackoverflow.com/a/43281413> +#### Getting All Files in Folder +<https://stackoverflow.com/a/612176> + +#### Getting File Name from Path +<https://stackoverflow.com/a/24386991> + +#### Path Value to Str +<https://stackoverflow.com/a/45401869> + +### Other +#### C++ Strings +<https://stackoverflow.com/a/3535904> + +#### Files Compiling without "Standard" C++ Library Access +<https://stackoverflow.com/a/10271117> + #### Reading In & Manipulating Image Files * <https://stackoverflow.com/a/59553786> * <https://stackoverflow.com/a/5420568> -### CUDA References +## CUDA References -#### Book Reference +### Book Reference "Cuda by Example", by Jason Sanders & Edward Kandrot -#### First CUDA Program +### First CUDA Program <https://developer.nvidia.com/blog/easy-introduction-cuda-c-and-c/> -#### Intro CUDA Tutorial +### Intro CUDA Tutorial <https://cuda-tutorial.readthedocs.io/en/latest/tutorials/tutorial01/> diff --git a/part_1/main.cu b/part_1/main.cu index 081c7e83ea73a404bcc45d7d24a4d9c16c8f4cac..83024c870ed4cc7d65281c9a3960cc8b6f1ea0f1 100644 --- a/part_1/main.cu +++ b/part_1/main.cu @@ -11,7 +11,7 @@ #include <iterator> #include <stdio.h> #include <stdlib.h> -#include <string.h> +#include <string> #include <vector> // User Import Headers. @@ -22,8 +22,9 @@ // Method Declaration. -path_validator_struct* validate_path(char* path_str); -void process_file(char* path_str); +path_validator_struct* validate_path(std::string path_str); +void process_dir(std::string path_str); +void process_file(std::string path_str); // void validate_path(char* path_str); // void compute(int a, int b); // __global__ void cuda_add(int a, int b, int* c); @@ -50,18 +51,20 @@ int main(int argc, char* argv[]) { // Correct number of args provided. Attempt to process. // Check data type. - char* path_str = argv[1]; + std::string path_str = argv[1]; path_validator_struct* return_struct = validate_path(path_str); int path_type = return_struct->file_type; - printf("File type: %i\n", path_type); if (return_struct->err_code) { std::cerr << "Error in is_regular_file: " << return_struct->err_code.message(); } free_path_validator_struct(return_struct); + // Handle based on provided type. if (path_type == TYPE_DIR) { - printf("Is dir. Skipping doing work for now.\n"); + // Process dir. + process_dir(path_str); } else if (path_type == TYPE_FILE) { + // Process file. process_file(path_str); } } @@ -77,11 +80,11 @@ int main(int argc, char* argv[]) { * Validates provided path and if valid, determines path type. * Returns struct of data. */ -path_validator_struct* validate_path(char* path_str) { +path_validator_struct* validate_path(std::string path_str) { int type_value = TYPE_OTHER; std::error_code ec; - // printf("path_str: \"%s\"\n", path_str); + std::cout << "path_str: \"" + path_str + "\"\n"; // Check if provided path exists. std::ifstream test_path_exists(path_str); @@ -103,9 +106,27 @@ path_validator_struct* validate_path(char* path_str) { /** - * + * Finds and processes all files in directory. + * Assumes directory is full of image files. + */ +void process_dir(std::string path_str) { + + // Process all files in directory. + for (const auto & entry : std::filesystem::directory_iterator(path_str)) { + // Get as string. + std::string file_path_str{entry.path().u8string()}; + // std::cout << file_path_str << std::endl; + + // Send individual file path for processing. + process_file(entry.path()); + } +} + + +/** + * Processes a single image file. */ -void process_file(char* path_str) { +void process_file(std::string path_str) { // Open input file. std::ifstream input_file; @@ -114,8 +135,11 @@ void process_file(char* path_str) { printf("Failed to open file \"%s\".\n", path_str); } + // Calculate output path location. + std::string base_filename = path_str.substr(path_str.find_last_of("/\\") + 1); + std::string output_path_str = "../output/" + base_filename; + // Open output file. - char* output_path_str = "../output/test_file.jpg"; std::ofstream output_file; output_file.open(output_path_str, std::ios::binary | std::ios::out); if (! output_file.good()) { @@ -144,6 +168,8 @@ void process_file(char* path_str) { + + // /* // * Program's main. Initializes and runs program. // */