当前位置: 首页>>代码示例>>C++>>正文


C++ String::CStr方法代码示例

本文整理汇总了C++中String::CStr方法的典型用法代码示例。如果您正苦于以下问题:C++ String::CStr方法的具体用法?C++ String::CStr怎么用?C++ String::CStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在String的用法示例。


在下文中一共展示了String::CStr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ConfigGlobHandler

void ApiListener::ConfigGlobHandler(Dictionary::Ptr& config, const String& path, const String& file)
{
	CONTEXT("Creating config update for file '" + file + "'");

	Log(LogNotice, "ApiListener")
	    << "Creating config update for file '" << file << "'";

	std::ifstream fp(file.CStr(), std::ifstream::binary);
	if (!fp)
		return;

	String content((std::istreambuf_iterator<char>(fp)), std::istreambuf_iterator<char>());
	config->Set(file.SubStr(path.GetLength()), content);
}
开发者ID:Nadahar,项目名称:icinga2,代码行数:14,代码来源:apilistener-sync.cpp

示例2: Run

/**
 * The entry point for the "object list" CLI command.
 *
 * @returns An exit status.
 */
int ObjectListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
{
	String objectfile = Application::GetObjectsPath();

	if (!Utility::PathExists(objectfile)) {
		Log(LogCritical, "cli")
		    << "Cannot open objects file '" << Application::GetObjectsPath() << "'.";
		Log(LogCritical, "cli", "Run 'icinga2 daemon -C' to validate config and generate the cache file.");
		return 1;
	}

	std::fstream fp;
	fp.open(objectfile.CStr(), std::ios_base::in);

	StdioStream::Ptr sfp = new StdioStream(&fp, false);
	unsigned long objects_count = 0;
	std::map<String, int> type_count;

	String message;
	String name_filter, type_filter;

	if (vm.count("name"))
		name_filter = vm["name"].as<std::string>();
	if (vm.count("type"))
		type_filter = vm["type"].as<std::string>();

	bool first = true;

	while (NetString::ReadStringFromStream(sfp, &message)) {
		PrintObject(std::cout, first, message, type_count, name_filter, type_filter);
		objects_count++;
	}

	sfp->Close();
	fp.close();

	if (vm.count("count")) {
		if (!first)
			std::cout << "\n";

		PrintTypeCounts(std::cout, type_count);
		std::cout << "\n";
	}

	Log(LogNotice, "cli")
	    << "Parsed " << objects_count << " objects.";

	return 0;
}
开发者ID:CodeOps,项目名称:icinga2,代码行数:54,代码来源:objectlistcommand.cpp

示例3: GetExePath

/**
 * Retrieves the full path of the executable.
 *
 * @param argv0 The first command-line argument.
 * @returns The path.
 */
String Application::GetExePath(const String& argv0)
{
	String executablePath;

#ifndef _WIN32
	char buffer[MAXPATHLEN];
	if (getcwd(buffer, sizeof(buffer)) == NULL) {
		BOOST_THROW_EXCEPTION(posix_error()
		    << boost::errinfo_api_function("getcwd")
		    << boost::errinfo_errno(errno));
	}

	String workingDirectory = buffer;

	if (argv0[0] != '/')
		executablePath = workingDirectory + "/" + argv0;
	else
		executablePath = argv0;

	bool foundSlash = false;
	for (size_t i = 0; i < argv0.GetLength(); i++) {
		if (argv0[i] == '/') {
			foundSlash = true;
			break;
		}
	}

	if (!foundSlash) {
		const char *pathEnv = getenv("PATH");
		if (pathEnv != NULL) {
			std::vector<String> paths;
			boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));

			bool foundPath = false;
			BOOST_FOREACH(String& path, paths) {
				String pathTest = path + "/" + argv0;

				if (access(pathTest.CStr(), X_OK) == 0) {
					executablePath = pathTest;
					foundPath = true;
					break;
				}
			}

			if (!foundPath) {
				executablePath.Clear();
				BOOST_THROW_EXCEPTION(std::runtime_error("Could not determine executable path."));
			}
		}
开发者ID:CodeOps,项目名称:icinga2,代码行数:55,代码来源:application.cpp

示例4: RotateFile

void PerfdataWriter::RotateFile(std::ofstream& output, const String& temp_path, const String& perfdata_path)
{
	ObjectLock olock(this);

	if (output.good()) {
		output.close();

		if (Utility::PathExists(temp_path)) {
			String finalFile = perfdata_path + "." + Convert::ToString((long)Utility::GetTime());
			if (rename(temp_path.CStr(), finalFile.CStr()) < 0) {
				BOOST_THROW_EXCEPTION(posix_error()
				    << boost::errinfo_api_function("rename")
				    << boost::errinfo_errno(errno)
				    << boost::errinfo_file_name(temp_path));
			}
		}
	}

	output.open(temp_path.CStr());

	if (!output.good())
		Log(LogWarning, "PerfdataWriter")
		    << "Could not open perfdata file '" << temp_path << "' for writing. Perfdata will be lost.";
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:24,代码来源:perfdatawriter.cpp

示例5: CollectPaths

void ConfigPackageUtility::CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths)
{
#ifndef _WIN32
	struct stat statbuf;
	int rc = lstat(path.CStr(), &statbuf);
	if (rc < 0)
		BOOST_THROW_EXCEPTION(posix_error()
		    << boost::errinfo_api_function("lstat")
		    << boost::errinfo_errno(errno)
		    << boost::errinfo_file_name(path));

	paths.push_back(std::make_pair(path, S_ISDIR(statbuf.st_mode)));
#else /* _WIN32 */
	struct _stat statbuf;
	int rc = _stat(path.CStr(), &statbuf);
	if (rc < 0)
		BOOST_THROW_EXCEPTION(posix_error()
		    << boost::errinfo_api_function("_stat")
		    << boost::errinfo_errno(errno)
		    << boost::errinfo_file_name(path));

	paths.push_back(std::make_pair(path, ((statbuf.st_mode & S_IFMT) == S_IFDIR)));
#endif /* _WIN32 */
}
开发者ID:Thomas-Gelf,项目名称:icinga2,代码行数:24,代码来源:configpackageutility.cpp

示例6: defined

HMODULE
#else /* _WIN32 */
void *
#endif /* _WIN32 */
Utility::LoadExtensionLibrary(const String& library)
{
	String path;
#if defined(_WIN32)
	path = library + ".dll";
#elif defined(__APPLE__)
	path = "lib" + library + ".dylib";
#else /* __APPLE__ */
	path = "lib" + library + ".so";
#endif /* _WIN32 */

	Log(LogInformation, "base", "Loading library '" + path + "'");

#ifdef _WIN32
	HMODULE hModule = LoadLibrary(path.CStr());

	if (hModule == NULL) {
		BOOST_THROW_EXCEPTION(win32_error()
		    << boost::errinfo_api_function("LoadLibrary")
		    << errinfo_win32_error(GetLastError())
		    << boost::errinfo_file_name(path));
	}
#else /* _WIN32 */
	void *hModule = dlopen(path.CStr(), RTLD_NOW);

	if (hModule == NULL) {
		BOOST_THROW_EXCEPTION(std::runtime_error("Could not load library '" + path + "': " + dlerror()));
	}
#endif /* _WIN32 */

	return hModule;
}
开发者ID:CSRedRat,项目名称:icinga2,代码行数:36,代码来源:utility.cpp

示例7: SignCsr

int PkiUtility::SignCsr(const String& csrfile, const String& certfile)
{
	std::stringstream msgbuf;
	char errbuf[120];

	InitializeOpenSSL();

	BIO *csrbio = BIO_new_file(csrfile.CStr(), "r");
	X509_REQ *req = PEM_read_bio_X509_REQ(csrbio, NULL, NULL, NULL);

	if (!req) {
		Log(LogCritical, "SSL")
		    << "Could not read X509 certificate request from '" << csrfile << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\"";
		return 1;
	}

	BIO_free(csrbio);

	boost::shared_ptr<X509> cert = CreateCertIcingaCA(X509_REQ_get_pubkey(req), X509_REQ_get_subject_name(req));

	X509_REQ_free(req);

	std::ofstream fpcert;
	fpcert.open(certfile.CStr());

	if (!fpcert) {
		Log(LogCritical, "cli")
		    << "Failed to open certificate file '" << certfile << "' for output";
		return 1;
	}

	fpcert << CertificateToString(cert);
	fpcert.close();

	return 0;
}
开发者ID:CodeOps,项目名称:icinga2,代码行数:36,代码来源:pkiutility.cpp

示例8: if

    FileStream::FileStream(const String& path, AccessMode accessMode)
        : handle(nullptr),
          canRead(false),
          canWrite(false)
    {
        BBAssert(path.Contains('\\') == false);

        if (path.IsEmpty())
            return;

        char mode[3] = { 'r', 'b', '\0' };
        if (accessMode == ReadOnly)
            mode[0] = 'r';
        else if (accessMode == WriteOnly)
            mode[0] = 'w';

        String absPath;
        if (Path::IsAbsolutePath(path) == false)
        {
            BBAssert(path.CStr()[0] != '/');
            absPath = Environment::GetWorkingDirectory() + path;
        }
        else
            absPath = path;

        handle = std::fopen(absPath.CStr(), mode);
        if (handle == nullptr)
        {
            canRead  = false;
            canWrite = false;
            return;
        }

        canRead  = (accessMode == FileStream::ReadOnly);
        canWrite = (accessMode == FileStream::WriteOnly);
    }
开发者ID:Darkttd,项目名称:Bibim,代码行数:36,代码来源:FileStream.iOS.cpp

示例9: OpenLogFile

/* must hold m_LogLock */
void ApiListener::OpenLogFile(void)
{
	String path = GetApiDir() + "log/current";

	std::fstream *fp = new std::fstream(path.CStr(), std::fstream::out | std::ofstream::app);

	if (!fp->good()) {
		Log(LogWarning, "ApiListener")
		    << "Could not open spool file: " << path;
		return;
	}

	m_LogFile = new StdioStream(fp, true);
	m_LogMessageCount = 0;
	SetLogMessageTimestamp(Utility::GetTime());
}
开发者ID:spjmurray,项目名称:icinga2,代码行数:17,代码来源:apilistener.cpp

示例10: GetTypeName

/**
 * Returns a human-readable type name of a type_info object.
 *
 * @param ti A type_info object.
 * @returns The type name of the object.
 */
String Utility::GetTypeName(const type_info& ti)
{
	String klass = ti.name();

#ifdef HAVE_GCC_ABI_DEMANGLE
	int status;
	char *realname = abi::__cxa_demangle(klass.CStr(), 0, 0, &status);

	if (realname != NULL) {
		klass = String(realname);
		free(realname);
	}
#endif /* HAVE_GCC_ABI_DEMANGLE */

	return klass;
}
开发者ID:h4ck3rm1k3,项目名称:strawberry,代码行数:22,代码来源:utility.cpp

示例11: Query

IdoPgsqlResult IdoPgsqlConnection::Query(const String& query)
{
	AssertOnWorkQueue();

	Log(LogDebug, "IdoPgsqlConnection")
	    << "Query: " << query;

	IncreaseQueryCount();

	PGresult *result = PQexec(m_Connection, query.CStr());

	if (!result) {
		String message = PQerrorMessage(m_Connection);
		Log(LogCritical, "IdoPgsqlConnection")
		    << "Error \"" << message << "\" when executing query \"" << query << "\"";

		BOOST_THROW_EXCEPTION(
		    database_error()
			<< errinfo_message(message)
			<< errinfo_database_query(query)
		);
	}

	char *rowCount = PQcmdTuples(result);
	m_AffectedRows = atoi(rowCount);

	if (PQresultStatus(result) == PGRES_COMMAND_OK) {
		PQclear(result);
		return IdoPgsqlResult();
	}

	if (PQresultStatus(result) != PGRES_TUPLES_OK) {
		String message = PQresultErrorMessage(result);
		PQclear(result);

		Log(LogCritical, "IdoPgsqlConnection")
		    << "Error \"" << message << "\" when executing query \"" << query << "\"";

		BOOST_THROW_EXCEPTION(
		    database_error()
			<< errinfo_message(message)
			<< errinfo_database_query(query)
		);
	}

	return IdoPgsqlResult(result, std::ptr_fun(PQclear));
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:47,代码来源:idopgsqlconnection.cpp

示例12: GetActiveStage

String ConfigPackageUtility::GetActiveStage(const String& packageName)
{
	String path = GetPackageDir() + "/" + packageName + "/active-stage";

	std::ifstream fp;
	fp.open(path.CStr());

	String stage;
	std::getline(fp, stage.GetData());

	fp.close();

	if (fp.fail())
		return "";

	return stage.Trim();
}
开发者ID:Thomas-Gelf,项目名称:icinga2,代码行数:17,代码来源:configpackageutility.cpp

示例13: catch

/**
 * Converts a dictionary to a JSON object.
 *
 * @param dictionary The dictionary.
 * @returns A JSON object that is equivalent to the dictionary. Values that
 *	    cannot be represented in JSON are omitted.
 */
cJSON *Dictionary::ToJson(void) const
{
	cJSON *json = cJSON_CreateObject();

	try {
		String key;
		Value value;
		BOOST_FOREACH(tie(key, value), m_Data) {
			cJSON_AddItemToObject(json, key.CStr(), value.ToJson());
		}
	} catch (...) {
		cJSON_Delete(json);
		throw;
	}

	return json;
}
开发者ID:h4ck3rm1k3,项目名称:strawberry,代码行数:24,代码来源:dictionary.cpp

示例14: String

String Base64::Encode(const String& input)
{
	BIO *biomem = BIO_new(BIO_s_mem());
	BIO *bio64 = BIO_new(BIO_f_base64());
	BIO_push(bio64, biomem);
	BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
	BIO_write(bio64, input.CStr(), input.GetLength());
	(void) BIO_flush(bio64);

	char *outbuf;
	long len = BIO_get_mem_data(biomem, &outbuf);

	String ret = String(outbuf, outbuf + len);
	BIO_free_all(bio64);

	return ret;
}
开发者ID:Icinga,项目名称:icinga2,代码行数:17,代码来源:base64.cpp

示例15: CreateStage

String ConfigPackageUtility::CreateStage(const String& packageName, const Dictionary::Ptr& files)
{
	String stageName = Utility::NewUniqueID();

	String path = GetPackageDir() + "/" + packageName;

	if (!Utility::PathExists(path))
		BOOST_THROW_EXCEPTION(std::invalid_argument("Package does not exist."));

	path += "/" + stageName;

	Utility::MkDirP(path, 0700);
	Utility::MkDirP(path + "/conf.d", 0700);
	Utility::MkDirP(path + "/zones.d", 0700);
	WriteStageConfig(packageName, stageName);

	bool foundDotDot = false;

	if (files) {
		ObjectLock olock(files);
		BOOST_FOREACH(const Dictionary::Pair& kv, files) {
			if (ContainsDotDot(kv.first)) {
				foundDotDot = true;
				break;
			}

			String filePath = path + "/" + kv.first;

			Log(LogInformation, "ConfigPackageUtility")
			    << "Updating configuration file: " << filePath;

			//pass the directory and generate a dir tree, if not existing already
			Utility::MkDirP(Utility::DirName(filePath), 0750);
			std::ofstream fp(filePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
			fp << kv.second;
			fp.close();
		}
	}

	if (foundDotDot) {
		Utility::RemoveDirRecursive(path);
		BOOST_THROW_EXCEPTION(std::invalid_argument("Path must not contain '..'."));
	}

	return stageName;
}
开发者ID:Thomas-Gelf,项目名称:icinga2,代码行数:46,代码来源:configpackageutility.cpp


注:本文中的String::CStr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。