Category: C++
How to convert a byte vector into to a 32bit word vector
How do you convert a vector of 8bit values (bytes) to a vector of 32bit values (words)? Why would you want to do such a thing? Well maybe you have a bytes stream that needs to be sent over a 32bit bus? You could use the std::vector constructor to construct a new vector on the…
C++ Iterating Scoped Enumerations
requirements Map non-integer values to scoped enum literals Use switch statements to catch missing enum cases in value lookup ( -Wswitch-enum allows default case) Use class template to iterate the enum mapped values Limitations Iterator needs to be given begin/end points, so you have to sync this end limit with the last entry in EncapsulatedEnum::Key…
C++ Singleton Enumerated Map
Features Maps enum type literals to strings (or any type) Singleton pattern ensure only single instance Encapsulation checks if key exists to prevent lookup errors/exceptions. C++17 version --std=c++17 -Wall -Wextra…
C++ Encapsulated VectorOfVectors
C++ Serialize Function
Convert an unsigned integer to a vector of bytes (char) The use of function template and argument deduction means you don't need to specialize the function template, you just call it with the unsigned int type and the compiler will deduce the width of the type. The function uses sizeof() to calculate the bitwise shift…
C++ Template argument deduction vs specialization
If you don't know the type at compile time you can just use the template parameter type and the compiler will deduce the type from the function call itself. For example, see the commented out c'tor below. This is great for typing the size of std::array function parameter. However you could come unstuck if a…
DSP Guitar Pedal with Cortex-M4F and C++
Hardware Design Brief The purpose of this project is to design, build a programmable guitar FX pedal using a Cortex-M4F micro and I2S. This will provide a platform for development and experimentation of DSP algorithms and techniques. This is also an experiment to use C++ in embedded development. Evaluating the 24bit ADC and DAC Digilent…