Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: conditionally enable mmap functionality #40

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

finger563
Copy link
Contributor

@finger563 finger563 commented Mar 30, 2023

  • Only enable include of csv2/mio.hpp in csv2/reader.hpp if sys/mman.h or windows.h can be found
    This helps on platforms such as ESP32 which do not have mmap support exposed through sys/mman.h (though they do have memory mapping support at a lower layer, so perhaps that could be utilized via a later PR).

Tested on ESP32 using the following code:

    //! [csv reader example]
    std::string csv_data =
      "filename, boxart filename, display name\n"
      "mario.nes, boxart/mario.jpg, Mario Bros.\n"
      "super_mario_1.nes, boxart/super_mario_bros_1.jpg, Super Mario Bros.\n"
      "super_mario_3.nes, boxart/super_mario_bros_3.jpg, Super Mario Bros. 3\n"
      "zelda.nes, boxart/zelda1.jpg, The Legend of Zelda\n"
      "zelda_2.nes, boxart/zelda2.jpg, The Legend of Zelda 2: the Adventure of Link\n"
      "mega_man.nes, boxart/megaman1.jpg, MegaMan\n"
      "metroid.nes, boxart/metroid1.jpg, Metroid\n"
      "pokemon_blue.gb, boxart/pokemon_blue.jpg, Pokemon Blue\n"
      "pokemon_red.gb, boxart/pokemon_red.jpg, Pokemon Red\n"
      "pokemon_yellow.gbc, boxart/pokemon_yellow.jpg, Pokemon Yellow\n"
      "links_awakening.gb, boxart/tloz_links_awakening.jpg, The Legend of Zelda: Link's Awakening\n"
      "links_awakening.gbc, boxart/tloz_links_awakening_dx.jpg, The Legend of Zelda: Link's Awakening DX";

    // create the csv reader object
    csv2::Reader<csv2::delimiter<','>,
                 csv2::quote_character<'"'>,
                 csv2::first_row_is_header<true>,
                 csv2::trim_policy::trim_whitespace> csv;
    if (csv.parse(csv_data)) {
      // print the header
      const auto header = csv.header();
      fmt::print("Header:\n\t");
      for (const auto cell: header) {
        std::string value;
        cell.read_value(value);
        fmt::print("'{}', ", value);
      }
      fmt::print("\n");
      // now print the items
      size_t row_index = 0;
      for (const auto row: csv) {
        fmt::print("Row {} values:\n\t", row_index);
        for (const auto cell: row) {
          std::string value;
          cell.read_value(value);
          fmt::print("'{}', ", value);
        }
        fmt::print("\n");
        row_index++;
      }
    }
    //! [csv reader example]

With the following output:
CleanShot 2023-03-30 at 15 02 42

* Only enable include of csv2/mio.hpp in csv2/reader.hpp if sys/mman.h or windows.h can be found
@p-ranav p-ranav merged commit 3e16a8a into p-ranav:master Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants