Skip to content

Commit

Permalink
Refactor Music module (#590)
Browse files Browse the repository at this point in the history
* change music to use string view

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Add artists to music data

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Update Music tests to use string view

Signed-off-by: Uilian Ries <uilianries@gmail.com>

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries authored May 26, 2024
1 parent e550bc6 commit 901ee78
Show file tree
Hide file tree
Showing 9 changed files with 1,326 additions and 1,316 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ set(FAKER_SOURCES
src/modules/movie/Movie.cpp
src/modules/movie/MovieData.cpp
src/modules/music/Music.cpp
src/modules/music/MusicData.cpp
src/modules/number/Number.cpp
src/modules/person/Person.cpp
src/modules/phone/Phone.cpp
Expand Down
8 changes: 4 additions & 4 deletions include/faker-cxx/Music.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <string_view>

namespace faker
{
Expand All @@ -16,7 +16,7 @@ class Music
* Music::artist() // "Nirvana"
* @endcode
*/
static std::string artist();
static std::string_view artist();

/**
* @brief Returns a random music genre.
Expand All @@ -27,7 +27,7 @@ class Music
* Music::genre() // "Rock"
* @endcode
*/
static std::string genre();
static std::string_view genre();

/**
* @brief Returns a random song name.
Expand All @@ -38,6 +38,6 @@ class Music
* Music::songName() // "Light My Fire"
* @endcode
*/
static std::string songName();
static std::string_view songName();
};
}
16 changes: 7 additions & 9 deletions src/modules/music/Music.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#include "faker-cxx/Music.h"

#include "data/Artists.h"
#include "data/Genres.h"
#include "data/SongNames.h"
#include "MusicData.h"
#include "faker-cxx/Helper.h"

namespace faker
{
std::string Music::artist()
std::string_view Music::artist()
{
return Helper::arrayElement<std::string>(artists);
return Helper::arrayElement(music::artists);
}

std::string Music::genre()
std::string_view Music::genre()
{
return Helper::arrayElement<std::string>(musicGenres);
return Helper::arrayElement(music::musicGenres);
}

std::string Music::songName()
std::string_view Music::songName()
{
return Helper::arrayElement<std::string>(songNames);
return Helper::arrayElement(music::songNames);
}
}
Loading

0 comments on commit 901ee78

Please sign in to comment.