Code Start

As we covered in the previous posts, I plan to build a blockchain like software because I want something that runs on Raspberry Pi and I also want a bit more control. I have selected C++ and Cloud9 as my tools. Now to use them.

I first created a new user for myself and potentially others who I might use my Cloud9 account. AWS has tutorials for all of this, that is how I learned. So with a new user and IDE in the cloud, I was ready to start.

I first wanted some standards. I wanted a comment standard to follow. So I read various coding standards for C++ and selected the ones that looked the most standard and new–Google got my attention. I will try to fit close to their standard. I noticed that they restricted the Boost library functions to use to only those approved to use. Most of the ones I was looking at were not approved.

After some tries and thought, I wrote this and like it (sorry it is not in the best font–Don’t know how to change that):

/**

Copyright 2018 Michael R. Wild

Permission is hereby granted, free of charge, to any person obtaining a copy of
 this software and associated documentation files (the "Software"), to deal in
 the Software without restriction, including without limitation the rights to
 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 the Software, and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

@file mcpmain.cpp
 @author Michael R. Wild
 @date 3/6/2018
 @version 0.0.1

@brief Master Control Program

@section DESCRIPTION

This is the description

@section CHANGES

20180306 Creation

*/

I decided to release the code and to use @-notation to capture relevant information. I liked the idea of having the information available to an editor. The MCP is a reference to the old TRON movie. I have to admit it took me days to decide on this and I read a lot of standards.

The main (not easy to show as I had to embed some characters) is just a group of demos. Still learning and guessing how to do all of this. I have not used the convention of std being defined before. I have not written formal C++ and was taken aback by some of the changes in standards I read. Now define the minimal and key a bit more. I also like the auto to define the obvious.

#include <iostream>
#include <ctime>
#include "mcp.cpp"

int main()
{
    
    MCPParms ourparms("some.xml"); // parms for program
	
	// Print a header of execution out
	auto result = std::time(nullptr);	
	std::cout << "Master Control Program " << std::endl;
	std::cout << "Local Time: " <<
	    std::asctime(std::localtime(&result)) << std::endl;
	    
	// Try to get the parms for the MCP
	std::cout << "Read in MCP controls " << std::endl;
	try
    {
        ourparms.load();
        std::string name = ourparms.get("mcp.programtext");
        std::string version = ourparms.get("mcp.version");
        std::cout << "Success: " << name << " " << version << std::endl;
    }
    catch (std::exception &e)
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
    
    // update something
    ourparms.put("mcp.more", "This is a test");
    
    // get update
    try
    {
        std::string name = ourparms.get("mcp.more");
        std::cout << "Success: " << name << " " << std::endl;
    }
    catch (std::exception &e)
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
    
    // save change
    try
    {
        ourparms.save();
        std::cout << "Saved!" << std::endl;
    }
    catch (std::exception &e)
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
    
    // Leave politely
    return 0;
}

The code read in an XML file into a tree structure. I really like this as I can just load data into a tree from a file and look it up and update it and even write it back. That gives me all sorts of ideas.

Next time I will expand the information into the includes. Once that happens this Blog will be caught up and I will have to code and Blog at the same time. I am thinking of blogging on Tuesdays and Thursday and code the other nights.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s