Mercurial > public > cpp-enigma
annotate enigma/enigma_utils.h @ 8:b90a41f0cd94
Created enigma_machine::army_str() & navy_str() functions for logging.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 29 Jun 2012 20:29:41 -0500 |
parents | 2792ca4ffa84 |
children | 424111a36ed7 |
rev | line source |
---|---|
bgneal@1 | 1 #ifndef CPP_ENIGMA_ENIGMA_UTILS_H |
bgneal@1 | 2 #define CPP_ENIGMA_ENIGMA_UTILS_H |
bgneal@1 | 3 // Copyright (C) 2012 by Brian Neal. |
bgneal@1 | 4 // This file is part of Cpp-Enigma, the Enigma Machine simulation. |
bgneal@1 | 5 // Cpp-Enigma is released under the MIT License (see License.txt). |
bgneal@1 | 6 // |
bgneal@1 | 7 // enigma_utils.h - This file contains common functions used throughout Cpp-Enigma. |
bgneal@1 | 8 |
bgneal@4 | 9 #include <string> |
bgneal@4 | 10 |
bgneal@1 | 11 namespace enigma |
bgneal@1 | 12 { |
bgneal@1 | 13 // This version of mod acts like Python's with respect to negative dividends. |
bgneal@1 | 14 inline int alpha_mod(int dividend) |
bgneal@1 | 15 { |
bgneal@1 | 16 if (dividend < 0) |
bgneal@1 | 17 { |
bgneal@1 | 18 dividend += 26; |
bgneal@1 | 19 } |
bgneal@1 | 20 return dividend % 26; |
bgneal@1 | 21 } |
bgneal@4 | 22 |
bgneal@4 | 23 // Removes spaces from a string and returns the resulting string: |
bgneal@4 | 24 std::string remove_spaces(const std::string& s); |
bgneal@1 | 25 } |
bgneal@1 | 26 |
bgneal@1 | 27 #endif |