本文整理汇总了C++中ustring::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ ustring::c_str方法的具体用法?C++ ustring::c_str怎么用?C++ ustring::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustring
的用法示例。
在下文中一共展示了ustring::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
map < unsigned int, ustring > resource_get_books(const ustring & templatefile)
{
map < unsigned int, ustring > books;
GKeyFile *keyfile = g_key_file_new();
if (g_key_file_load_from_file(keyfile, templatefile.c_str(), G_KEY_FILE_NONE, NULL)) {
vector < unsigned int >ids = books_type_to_ids(btUnknown);
for (unsigned int i = 0; i < ids.size(); i++) {
ustring english_name = books_id_to_english(ids[i]);
gchar *value;
value = g_key_file_get_string(keyfile, resource_template_books_group(), english_name.c_str(), NULL);
if (value) {
books[i] = value;
g_free(value);
}
}
g_key_file_free(keyfile);
}
return books;
}
示例2: in
ReadText::ReadText(const ustring & file, bool silent, bool trimming)
{
// Reads the text and stores it line by line, trimmed, into "lines".
// If "silent" is true, then no exception will be thrown in case of an error.
// The lines will be trimmed if "trimming" is true.
ifstream in(file.c_str());
if (!in) {
if (!silent) {
cerr << _("Error opening file ") << file << endl;
throw;
}
return;
}
string s;
while (getline(in, s)) {
if (trimming)
s = trim(s);
lines.push_back(s);
}
}
示例3: operator
inline void operator() (ustring name, Dual2<R> &result, const Dual2<S> &s,
const S &sp,
ShaderGlobals *sg, const NoiseParams *opt) const {
if (name == Strings::uperlin || name == Strings::noise) {
PeriodicNoise noise;
noise(result, s, sp);
} else if (name == Strings::perlin || name == Strings::snoise) {
PeriodicSNoise snoise;
snoise(result, s, sp);
} else if (name == Strings::cell) {
PeriodicCellNoise cellnoise;
cellnoise(result.val(), s.val(), sp);
result.clear_d();
} else if (name == Strings::gabor) {
GaborPNoise gnoise;
gnoise (name, result, s, sp, sg, opt);
} else {
((ShadingContext *)sg->context)->error ("Unknown noise type \"%s\"", name.c_str());
}
}
示例4: set_style
void EditorActionChangeParagraphStyle::set_style (const ustring& style)
{
// Define the work area.
GtkTextIter startiter;
gtk_text_buffer_get_start_iter (paragraph->textbuffer, &startiter);
GtkTextIter enditer;
gtk_text_buffer_get_end_iter (paragraph->textbuffer, &enditer);
// Apply the style in such a way that the paragraph style is always applied first,
// then after that the character styles.
vector <ustring> current_character_styles = get_character_styles_between_iterators (startiter, enditer);
gtk_text_buffer_remove_all_tags (paragraph->textbuffer, &startiter, &enditer);
gtk_text_buffer_apply_tag_by_name (paragraph->textbuffer, style.c_str(), &startiter, &enditer);
for (unsigned int i = 0; i < current_character_styles.size(); i++) {
if (!current_character_styles[i].empty()) {
gtk_text_buffer_get_iter_at_offset (paragraph->textbuffer, &startiter, i);
enditer = startiter;
gtk_text_iter_forward_char (&enditer);
gtk_text_buffer_apply_tag_by_name (paragraph->textbuffer, current_character_styles[i].c_str(), &startiter, &enditer);
}
}
}
示例5:
YesNoAlwaysDialog::YesNoAlwaysDialog(const ustring& message, bool default_yes)
{
gtkbuilder = gtk_builder_new ();
gtk_builder_add_from_file (gtkbuilder, gw_build_filename (Directories->get_package_data(), "gtkbuilder.yesnoalwaysdialog.xml").c_str(), NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "dialog"));
label = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "label"));
gtk_label_set_text (GTK_LABEL (label), message.c_str());
checkbutton = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "checkbutton"));
// Add the buttons. In the standard question dialog, the Yes is at the right, then the No following to the left.
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_NO, GTK_RESPONSE_NO);
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_YES, GTK_RESPONSE_YES);
if (default_yes)
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
else
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
}
示例6: cache_by_user
bool WinGroups::cache_by_user(const ustring& name, const ustring& dom)
{
// Cache groups that contains USER "name".
const DWORD dwLevel = 0, dwPrefMaxLen = MAX_PREFERRED_LENGTH, dwFlags = LG_INCLUDE_INDIRECT;
DWORD dwEntriesRead = 0, dwTotalEntries = 0;
NET_API_STATUS nStatus;
clear();
m_dom = dom;
LPGROUP_USERS_INFO_0 info = nullptr;
nStatus = ::NetUserGetLocalGroups(m_dom.c_str(), name.c_str(), dwLevel, dwFlags, (PBYTE*)&info, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
if (nStatus == NERR_Success || nStatus == ERROR_MORE_DATA) {
for (DWORD i = 0; i < dwEntriesRead; ++i) {
GroupInfo gtmp;
gtmp.name = info[i].grui0_name;
gtmp.comm = Group::get_comm(info[i].grui0_name);
push_back(gtmp);
}
::NetApiBufferFree(info);
}
return (NERR_Success == nStatus);
}
示例7: windowsoutpost_telnet
bool windowsoutpost_telnet(const ustring & hostname)
// This makes a connection with the Outpost on "host" and then disconnects again.
// It returns true if this worked out.
{
bool success = false;
struct sockaddr_in address;
struct hostent *host;
int sock;
host = gethostbyname(hostname.c_str());
if (host) {
#ifdef WIN32
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) != SOCKET_ERROR)
#else
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) >= 0)
#endif
{
address.sin_family = AF_INET;
memcpy(&address.sin_addr, host->h_addr_list[0], sizeof(address.sin_addr));
#ifdef WIN32
WSAHtons(sock, 51515, &address.sin_port);
if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == SOCKET_ERROR)
#else
address.sin_port = htons(51515);
if (connect(sock, (struct sockaddr *)&address, sizeof(address)))
#endif
{
; // success = false;
} else {
success = true;
}
#ifdef WIN32
closesocket(sock);
#else
close(sock);
#endif
}
}
return success;
}
示例8: scan_music_dir
void AudioOpenAL::scan_music_dir (const ustring& path,
vector<MusicFile>& files, MusicType type) {
double len;
ustring file_path;
MusicFile entry;
logger.fineln ("searching %s for music files", path.c_str ());
try {
Dir dir (path);
for (DirIterator it = dir.begin (); it != dir.end (); it++) {
if ((*it)[0] == '.')
continue;
file_path = path + (*it);
MplayerDecoder dec;
len = dec.get_length (file_path);
if (len <= 0)
continue;
if (type == MT_GameShort && len > 150) {
continue;
}
if (type == MT_GameLong && len <= 150) {
continue;
}
logger.fineln ("found music file %s", file_path.c_str ());
entry.filename = file_path;
entry.played = false;
files.push_back (entry);
}
} catch (FileError) {
}
}
示例9: string
std::string
OSLCompilerImpl::retrieve_source (ustring filename, int line)
{
// If we don't already have the file open, open it
if (filename != m_last_sourcefile) {
// If we have another file open, close that one
if (m_sourcefile)
fclose (m_sourcefile);
m_last_sourcefile = filename;
m_sourcefile = fopen (filename.c_str(), "r");
if (! m_sourcefile) {
m_last_sourcefile = ustring();
return "<not found>";
}
}
// If we want something *before* the last line read in the open file,
// rewind to the beginning.
if (m_last_sourceline > line) {
rewind (m_sourcefile);
m_last_sourceline = 0;
}
// Now read lines up to and including the file we want.
char buf[10240];
while (m_last_sourceline < line) {
if (fgets (buf, sizeof(buf), m_sourcefile))
++m_last_sourceline;
else
break;
}
// strip trailing newline
if (buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = '\0';
return std::string (buf);
}
示例10: cache_by_group
bool WinUsers::cache_by_group(const ustring& group, const ustring& dom) {
// Cache members of group "name".
const DWORD dwLevel = 1, dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0, dwTotalEntries = 0;
ULONG_PTR dwResumeHandle = 0;
NET_API_STATUS nStatus;
clear();
m_group = group;
m_dom = dom;
do {
PLOCALGROUP_MEMBERS_INFO_1 info = nullptr;
nStatus = ::NetLocalGroupGetMembers(m_dom.c_str(), group.c_str(), dwLevel, (PBYTE*) &info,
dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
if (NERR_Success == nStatus || ERROR_MORE_DATA == nStatus) {
PLOCALGROUP_MEMBERS_INFO_1 ptr = info;
for (DWORD i = 0; i < dwEntriesRead && ptr; ++i, ++ptr) {
push_back(UserInfo(UserBuf(ptr->lgrmi1_name).data()));
}
::NetApiBufferFree(info);
}
} while (ERROR_MORE_DATA == nStatus);
return (NERR_Success == nStatus);
}
示例11: get_context
ustring CheckMatchingPairs::get_context(ustring & line, unsigned int offset)
// Returns the context at offset: A couple of words before and after.
{
// Result.
ustring returnvalue;
// Load text into buffer.
GtkTextBuffer *textbuffer;
textbuffer = gtk_text_buffer_new(NULL);
gtk_text_buffer_set_text(textbuffer, line.c_str(), -1);
// Iterators.
GtkTextIter iter1;
GtkTextIter iter2;
// Find boundaries of context to return.
gtk_text_buffer_get_iter_at_offset(textbuffer, &iter1, offset);
iter2 = iter1;
gtk_text_iter_backward_word_starts(&iter1, 2);
gtk_text_iter_forward_word_ends(&iter2, 2);
return gtk_text_iter_get_text(&iter1, &iter2);
// Free memory
g_object_unref(textbuffer);
// Give us the result.
return returnvalue;
}
示例12: colorspace_is_data
bool ColorSpaceManager::colorspace_is_data(ustring colorspace)
{
if (colorspace == u_colorspace_auto || colorspace == u_colorspace_raw ||
colorspace == u_colorspace_srgb) {
return false;
}
#ifdef WITH_OCIO
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
if (!config) {
return false;
}
try {
OCIO::ConstColorSpaceRcPtr space = config->getColorSpace(colorspace.c_str());
return space && space->isData();
}
catch (OCIO::Exception &) {
return false;
}
#else
return false;
#endif
}
示例13: mechon_mamre_copyright
bool mechon_mamre_copyright(const ustring & inputfile)
// Returns true is a file has "Copyright" and "Mechon Mamre" in it.
{
// Read the file.
gchar *contents;
gsize length;
GError *error = NULL;
if (!g_file_get_contents(inputfile.c_str(), &contents, &length, &error)) {
gw_critical(error->message);
g_error_free(error);
return false;
}
// Search for the signature.
char *mechonmamre = g_strstr_len(contents, 400, _("Mechon Mamre"));
if (mechonmamre) {
mechonmamre = g_strstr_len(contents, 400, _("Copyright"));
}
// Free memory and return result.
g_free(contents);
if (mechonmamre)
return true;
else
return false;
}
示例14: lock
int
RendererServices::pointcloud_search (ShaderGlobals *sg,
ustring filename, const OSL::Vec3 ¢er,
float radius, int max_points, bool sort,
size_t *out_indices,
float *out_distances, int derivs_offset)
{
#if USE_PARTIO
if (! filename)
return 0;
PointCloud *pc = PointCloud::get(filename);
if (pc == NULL) { // The file failed to load
sg->context->shadingsys().error ("pointcloud_search: could not open \"%s\"", filename.c_str());
return 0;
}
spin_lock lock (pc->m_mutex);
Partio::ParticlesDataMutable *cloud = pc->m_partio_cloud;
if (cloud == NULL) { // The file failed to load
sg->context->shadingsys().error ("pointcloud_search: could not open \"%s\"", filename.c_str());
return 0;
}
// Early exit if the pointcloud contains no particles.
if (cloud->numParticles() == 0)
return 0;
// If we need derivs of the distances, we'll need access to the
// found point's positions.
Partio::ParticleAttribute *pos_attr = NULL;
if (derivs_offset) {
pos_attr = pc->m_attributes[u_position].get();
if (! pos_attr)
return 0; // No "position" attribute -- fail
}
ASSERT (sizeof(size_t) == sizeof(Partio::ParticleIndex) &&
"Only will work if Partio ParticleIndex is the size of a size_t");
// FIXME -- if anybody cares about an architecture in which that is not
// the case, we can easily allocate local space to retrieve the indices,
// then copy them back to the caller's indices.
Partio::ParticleIndex *indices = (Partio::ParticleIndex *)out_indices;
float *dist2 = out_distances;
if (! dist2) // If not supplied, allocate our own
dist2 = (float *)sg->context->alloc_scratch (max_points*sizeof(float), sizeof(float));
float finalRadius;
int count = cloud->findNPoints (¢er[0], max_points, radius,
indices, dist2, &finalRadius);
// If sorting, allocate some temp space and sort the distances and
// indices at the same time.
if (sort && count > 1) {
SortedPointRecord *sorted = (SortedPointRecord *) sg->context->alloc_scratch (count * sizeof(SortedPointRecord), sizeof(SortedPointRecord));
for (int i = 0; i < count; ++i)
sorted[i] = SortedPointRecord (dist2[i], indices[i]);
std::sort (sorted, sorted+count, SortedPointCompare());
for (int i = 0; i < count; ++i) {
dist2[i] = sorted[i].first;
indices[i] = sorted[i].second;
}
}
if (out_distances) {
// Convert the squared distances to straight distances
for (int i = 0; i < count; ++i)
out_distances[i] = sqrtf(dist2[i]);
if (derivs_offset) {
// We are going to need the positions if we need to compute
// distance derivs
OSL::Vec3 *positions = (OSL::Vec3 *) sg->context->alloc_scratch (sizeof(OSL::Vec3) * count, sizeof(float));
cloud->data (*pos_attr, count, indices, true, (void *)positions);
const OSL::Vec3 &dCdx = (¢er)[1];
const OSL::Vec3 &dCdy = (¢er)[2];
float *d_distance_dx = out_distances + derivs_offset;
float *d_distance_dy = out_distances + derivs_offset * 2;
for (int i = 0; i < count; ++i) {
d_distance_dx[i] = 1.0f / out_distances[i] *
((center.x - positions[i].x) * dCdx.x +
(center.y - positions[i].y) * dCdx.y +
(center.z - positions[i].z) * dCdx.z);
d_distance_dy[i] = 1.0f / out_distances[i] *
((center.x - positions[i].x) * dCdy.x +
(center.y - positions[i].y) * dCdy.y +
(center.z - positions[i].z) * dCdy.z);
}
}
}
return count;
#else
return 0;
#endif
}
示例15: Open
HANDLE Facade::Open(const ustring& path, ACCESS_MASK access, DWORD share, PSECURITY_ATTRIBUTES sa, DWORD creat, DWORD flags)
{
// LogTrace(L"'%s', 0x%08X, 0x%08X, %p\n", path.c_str(), access, share, sa);
return CheckHandleErr(::CreateFileW(path.c_str(), access, share, sa, creat, flags, nullptr));
}