BCS c++ function


To use c++ functions the header definitions, implementation methods and the mainline must be properly configured.

The header file for our class is first.
[codesyntax lang=”cpp”]

/**
 * fxgen2h.h
 *
 *  Created on: Aug 28, 2017
 *  @author    Author: archman
 */
#ifndef FXGENH_H_
#define FXGENH_H_
#include <boost/algorithm/string/replace.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <string>
using namespace std;
const int sizeOfStringArray = 1000;
/**
 * This is some test Doc Text
 */
struct mods {
	string from;
	string to;
};
struct mod_rec {
	int numPair;
	mods mp[15];
};
class fxcl {
/**
 * Private  Declarations Go Here
 */
private:
/**
 * Public  Declarations Go Here
 */
public:
	int fin(string, string[]);
	void fot(string otf, string stv[sizeOfStringArray], int cnt);
	void fileCopy(string fin, string fot);
	bool forceDirectories(string path);
	void upd(mod_rec rmrp, string stv[sizeOfStringArray], int cnt);
	string fixPath(string inPath, string fName);
};
#endif /* FXGENH_H_ */

[/codesyntax]
The implementation of the class follows.
[codesyntax lang=”cpp”]

/*
 * fxgen2h.cpp
 *
 *  Created on: Aug 28, 2017
 *      Author: archman
 */
#include "fxgenh.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>
using namespace std;
/**
 *This program designed
 */
void fxcl::fileCopy(string fin, string fot) {
	std::ifstream src(fin, std::ios::binary);
	std::ofstream dst(fot, std::ios::binary);
	dst << src.rdbuf();
}
int fxcl::fin(string inf, string stv[sizeOfStringArray]) {
	string line;
	int lcnt = 0;
	ifstream myfile(inf);
	if (myfile.is_open()) {
		while (getline(myfile, line)) {
			stv[lcnt] = line + "\n";
			lcnt++;
		}
		myfile.close();
		return lcnt;
	}
	else
		cout << "Unable to open file";
	return lcnt;
}
bool fxcl::forceDirectories(string path) {
	boost::filesystem::path dir(path);
	if (!(boost::filesystem::exists(dir))) {
		std::cout << path << " Doesn't Exists" << std::endl;
		if (boost::filesystem::create_directory(dir))
			std::cout << path << " Successfully Created !" << std::endl;
		return true;
	} else {
		return false;
	}
}
void fxcl::fot(string otf, string stv[sizeOfStringArray], int cnt) {
	string line;
	int ii = 0;
	ofstream myfile(otf);
	while (ii < cnt) {
		line = stv[ii];
		myfile << line;
		ii++;
	}
	myfile.close();
}
void fxcl::upd(mod_rec rmrp, string stv[sizeOfStringArray], int cnt) {
	int ii = rmrp.numPair;
	string rline;
	int j = 0;
	while (j < cnt) {
		int i = 0;
		while (i <= ii) {
			boost::replace_all(stv[j], rmrp.mp[i].from, rmrp.mp[i].to);
			i++;
		}
		rline = stv[j];
		j++;
	}
}
string fxcl::fixPath(string inPath, string fName){
  return inPath + fName;
}

[/codesyntax]
Finally we include out main or calling program.
[codesyntax lang=”cpp”]

//============================================================================
// Name        : fxgen2p.cpp
// Author      : Mr. Arch Brooks
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
/*! \mainpage My Personal Index Page
 *
 * \section intro_sec Introduction
 *
 * This is the introduction.
 *
 * \section install_sec Installation
 *
 * \subsection step1 Step 1: Opening the box
 *
 * etc...
 */
#include <iostream>
#include "fxgenh.h"
using namespace std;
int main(int argc, char* argv[]) {
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	fxcl fx;
	string rp;
	rp = fx.fixPath("/root/", "TestProg");
	cout << rp << endl;
	return 0;
}

[/codesyntax]
The output from the execution is as follows.
[codesyntax lang=”text”]

!!!Hello World!!!
/root/TestProg

[/codesyntax]
 
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *