diff options
author | Oran Juice <oranjuices@hotmail.com> | 2014-10-02 21:35:27 +0530 |
---|---|---|
committer | Oran Juice <oranjuices@hotmail.com> | 2014-10-02 21:45:31 +0530 |
commit | d683c8c724b59b2e8d01dcb45698c44b08186813 (patch) | |
tree | f226453543492862a2c9cd15b18c0a5545f2397e /src/mnemonics | |
parent | Cut short word lists to 1626 words, added attribution to Electrum, some bug f... (diff) | |
download | monero-d683c8c724b59b2e8d01dcb45698c44b08186813.tar.xz |
Use reference types on LHS when using language methods
Diffstat (limited to 'src/mnemonics')
-rw-r--r-- | src/mnemonics/electrum-words.cpp | 10 | ||||
-rw-r--r-- | src/mnemonics/electrum-words.h | 2 | ||||
-rw-r--r-- | src/mnemonics/english.h | 10 | ||||
-rw-r--r-- | src/mnemonics/japanese.h | 10 | ||||
-rw-r--r-- | src/mnemonics/language_base.h | 48 | ||||
-rw-r--r-- | src/mnemonics/old_english.h | 10 | ||||
-rw-r--r-- | src/mnemonics/portuguese.h | 10 | ||||
-rw-r--r-- | src/mnemonics/singleton.h | 18 | ||||
-rw-r--r-- | src/mnemonics/spanish.h | 10 |
9 files changed, 114 insertions, 14 deletions
diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp index e644e0cbf..053941194 100644 --- a/src/mnemonics/electrum-words.cpp +++ b/src/mnemonics/electrum-words.cpp @@ -95,14 +95,13 @@ namespace it->substr(0, Language::unique_prefix_length) : *it); } } - std::unordered_map<std::string, uint32_t> word_map; - std::unordered_map<std::string, uint32_t> trimmed_word_map; + // Iterate through all the languages and find a match for (std::vector<Language::Base*>::iterator it1 = language_instances.begin(); it1 != language_instances.end(); it1++) { - word_map = (*it1)->get_word_map(); - trimmed_word_map = (*it1)->get_trimmed_word_map(); + std::unordered_map<std::string, uint32_t> &word_map = (*it1)->get_word_map(); + std::unordered_map<std::string, uint32_t> &trimmed_word_map = (*it1)->get_trimmed_word_map(); // To iterate through seed words std::vector<std::string>::const_iterator it2; // To iterate through trimmed seed words @@ -285,7 +284,6 @@ namespace crypto if (sizeof(src.data) % 4 != 0 || sizeof(src.data) == 0) return false; - std::vector<std::string> word_list; Language::Base *language; if (language_name == "English") { @@ -307,7 +305,7 @@ namespace crypto { return false; } - word_list = language->get_word_list(); + std::vector<std::string> &word_list = language->get_word_list(); // To store the words for random access to add the checksum word later. std::vector<std::string> words_store; diff --git a/src/mnemonics/electrum-words.h b/src/mnemonics/electrum-words.h index 1535fff1b..3be4b1ccc 100644 --- a/src/mnemonics/electrum-words.h +++ b/src/mnemonics/electrum-words.h @@ -81,7 +81,7 @@ namespace crypto /*! * \brief Gets a list of seed languages that are supported. - * \param languages The vector is set to the list of languages. + * \param languages A vector is set to the list of languages. */ void get_language_list(std::vector<std::string> &languages); diff --git a/src/mnemonics/english.h b/src/mnemonics/english.h index ee2e248d9..e596f7b03 100644 --- a/src/mnemonics/english.h +++ b/src/mnemonics/english.h @@ -27,6 +27,12 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*!
+ * \file english.h
+ *
+ * \brief English word list and map.
+ */
+
#ifndef ENGLISH_H
#define ENGLISH_H
@@ -35,6 +41,10 @@ #include "language_base.h"
#include <string>
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
class English: public Base
diff --git a/src/mnemonics/japanese.h b/src/mnemonics/japanese.h index 1c53a808e..2e77aa257 100644 --- a/src/mnemonics/japanese.h +++ b/src/mnemonics/japanese.h @@ -27,6 +27,12 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*!
+ * \file japanese.h
+ *
+ * \brief Japanese word list and map.
+ */
+
#ifndef JAPANESE_H
#define JAPANESE_H
@@ -35,6 +41,10 @@ #include "language_base.h"
#include <string>
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
class Japanese: public Base
diff --git a/src/mnemonics/language_base.h b/src/mnemonics/language_base.h index b8b6a162f..1d08095d7 100644 --- a/src/mnemonics/language_base.h +++ b/src/mnemonics/language_base.h @@ -1,3 +1,9 @@ +/*!
+ * \file language_base.h
+ *
+ * \brief Language Base class for Polymorphism.
+ */
+
#ifndef LANGUAGE_BASE_H
#define LANGUAGE_BASE_H
@@ -5,16 +11,28 @@ #include <unordered_map>
#include <string>
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
- const int unique_prefix_length = 4;
+ const int unique_prefix_length = 4; /*!< Length of the prefix of all words guaranteed to be unique */
+ /*!
+ * \class Base
+ * \brief A base language class which all languages have to inherit from for
+ * Polymorphism.
+ */
class Base
{
protected:
- std::vector<std::string> *word_list;
- std::unordered_map<std::string, uint32_t> *word_map;
- std::unordered_map<std::string, uint32_t> *trimmed_word_map;
- std::string language_name;
+ std::vector<std::string> *word_list; /*!< A pointer to the array of words */
+ std::unordered_map<std::string, uint32_t> *word_map; /*!< hash table to find word's index */
+ std::unordered_map<std::string, uint32_t> *trimmed_word_map; /*!< hash table to find word's trimmed index */
+ std::string language_name; /*!< Name of language */
+ /*!
+ * \brief Populates the word maps after the list is ready.
+ */
void populate_maps()
{
int ii;
@@ -22,9 +40,9 @@ namespace Language for (it = word_list->begin(), ii = 0; it != word_list->end(); it++, ii++)
{
(*word_map)[*it] = ii;
- if (it->length() > 4)
+ if (it->length() > unique_prefix_length)
{
- (*trimmed_word_map)[it->substr(0, 4)] = ii;
+ (*trimmed_word_map)[it->substr(0, unique_prefix_length)] = ii;
}
else
{
@@ -39,18 +57,34 @@ namespace Language word_map = new std::unordered_map<std::string, uint32_t>;
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
}
+ /*!
+ * \brief Returns a pointer to the word list.
+ * \return A pointer to the word list.
+ */
const std::vector<std::string>& get_word_list() const
{
return *word_list;
}
+ /*!
+ * \brief Returns a pointer to the word map.
+ * \return A pointer to the word map.
+ */
const std::unordered_map<std::string, uint32_t>& get_word_map() const
{
return *word_map;
}
+ /*!
+ * \brief Returns a pointer to the trimmed word map.
+ * \return A pointer to the trimmed word map.
+ */
const std::unordered_map<std::string, uint32_t>& get_trimmed_word_map() const
{
return *trimmed_word_map;
}
+ /*!
+ * \brief Returns the name of the language.
+ * \return Name of the language.
+ */
std::string get_language_name() const
{
return language_name;
diff --git a/src/mnemonics/old_english.h b/src/mnemonics/old_english.h index 4e40b1730..21772cdc3 100644 --- a/src/mnemonics/old_english.h +++ b/src/mnemonics/old_english.h @@ -27,6 +27,12 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*!
+ * \file old_english.h
+ *
+ * \brief Old English word list and map.
+ */
+
#ifndef OLD_ENGLISH_H
#define OLD_ENGLISH_H
@@ -35,6 +41,10 @@ #include "language_base.h"
#include <string>
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
class OldEnglish: public Base
diff --git a/src/mnemonics/portuguese.h b/src/mnemonics/portuguese.h index 06d53f176..5b88a0686 100644 --- a/src/mnemonics/portuguese.h +++ b/src/mnemonics/portuguese.h @@ -26,6 +26,12 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*!
+ * \file portuguese.h
+ *
+ * \brief Portuguese word list and map.
+ */
+
#ifndef PORTUGUESE_H
#define PORTUGUESE_H
@@ -34,6 +40,10 @@ #include "language_base.h"
#include <string>
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
class Portuguese: public Base
diff --git a/src/mnemonics/singleton.h b/src/mnemonics/singleton.h index 74cc290fc..5a86c2e7c 100644 --- a/src/mnemonics/singleton.h +++ b/src/mnemonics/singleton.h @@ -26,8 +26,26 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*!
+ * \file singleton.h
+ *
+ * \brief A singleton helper class based on template.
+ */
+
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
+ /*!
+ * \class Singleton
+ *
+ * \brief Single helper class.
+ *
+ * Do Language::Singleton<YourClass>::instance() to create a singleton instance
+ * of `YourClass`.
+ */
template <class T>
class Singleton
{
diff --git a/src/mnemonics/spanish.h b/src/mnemonics/spanish.h index c205adc95..efa71a202 100644 --- a/src/mnemonics/spanish.h +++ b/src/mnemonics/spanish.h @@ -27,6 +27,12 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*!
+ * \file spanish.h
+ *
+ * \brief Spanish word list and map.
+ */
+
#ifndef SPANISH_H
#define SPANISH_H
@@ -35,6 +41,10 @@ #include "language_base.h"
#include <string>
+/*!
+ * \namespace Language
+ * \brief Mnemonic language related namespace.
+ */
namespace Language
{
class Spanish: public Base
|