/*
 * heading.h
 *
 * This file contains all the includes that are needed by the project to work
 *
 *  Created on: Jul 23, 2015
 *      Author: jjpalacios
 */

#ifndef HEADING_H_
#define HEADING_H_

#include <algorithm>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>

#include "./utils/ClbException.h"

#define Infd std::numeric_limits<double>::max()
#define Inff std::numeric_limits<float>::max()
#define Infi std::numeric_limits<int>::max()

#ifndef NULL
#define NULL   ((void *) 0)
#endif

#if defined(_WIN32)

static const std::string FSEP = "\\";
typedef long long off64_t;
#include <direct.h>

static void makeDir(const char* dirname) {
	_mkdir(dirname);
}

static char* getWorkDir(char* buffer, int maxLength) {
	return _getcwd(buffer, maxLength);
}

#else //#######################################################################

static const std::string FSEP = "/";
#include <sys/stat.h>

static void makeDir(const char* dirname) {
	mkdir(dirname, 0777); // notice that 777 is different than 0777
}

#include <unistd.h>

static char* getWorkDir(char* buffer, int maxLength) {
	return getcwd(buffer, maxLength);
}

#endif

template<typename T>
inline std::string valueToString(T value) {
	std::stringstream ss;
	ss << value; return ss.str();
}

inline std::string toUpper(std::string str) {
	std::transform(str.begin(), str.end(),str.begin(), ::toupper);
	return str;
}

static std::vector< std::string > fieldsFromCSV(const std::string &line) {
	std::vector< std::string > fields;
	std::string currentField = "";

	for(int i=0; i < (int)line.length(); i++) {
		if(line[i] == ';' || line[i] == ',') {
			fields.push_back(currentField);
			currentField.clear();
		}
		else if(line[i] != '\r' && line[i] != '\n')
			currentField.push_back(line[i]);
	}
	if(line.length() > 0)
		fields.push_back(currentField);

	return fields;
}

#endif /* HEADING_H_ */
