|
degate 0.1.1
|
00001 /* -*-c++-*- 00002 00003 This file is part of the IC reverse engineering tool degate. 00004 00005 Copyright 2008, 2009, 2010 by Martin Schobert 00006 00007 Degate is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 any later version. 00011 00012 Degate is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with degate. If not, see <http://www.gnu.org/licenses/>. 00019 00020 */ 00021 00022 #ifndef __DEGATEHELPER_H__ 00023 #define __DEGATEHELPER_H__ 00024 00025 00026 #define LENGTH_TO_MAX(l) (l > 0 ? l - 1 : 0) 00027 00028 namespace degate { 00029 00030 /** 00031 * Calculate the next higher power of two for a value \p i with i > 0. 00032 */ 00033 template<typename IntegerType> 00034 IntegerType next_power_of_two(IntegerType i) { 00035 IntegerType rval = 1; 00036 while(rval < i) rval <<= 1; 00037 return rval; 00038 } 00039 00040 /** 00041 * Tokenize a string. 00042 * @param str That is the string to tokenize, e.g. 00043 * "hello world. \"foo bar\"". This would result 00044 * in three tokens. 00045 */ 00046 std::vector<std::string> tokenize(std::string const& str); 00047 00048 /** 00049 * Write a string to a temp file. 00050 * @param dir The directory, where the temp file should be created. 00051 * @param content The file content. 00052 * @return Returns the temp file name including the directory part. 00053 */ 00054 std::string write_string_to_temp_file(std::string const& dir, 00055 std::string const& content); 00056 00057 /** 00058 * Write a string to a file. 00059 * @param path Path to file. 00060 * @param content The file content. 00061 */ 00062 void write_string_to_file(std::string const& path, 00063 std::string const& content); 00064 00065 00066 /** 00067 * Execute a command. 00068 * @param command The command to execute. 00069 * @param params list of parameters. 00070 * @returns Returns the exit code. 00071 */ 00072 int execute_command(std::string const& command, std::list<std::string> const& params); 00073 } 00074 00075 #endif
1.7.4