本文整理汇总了C++中CompString::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ CompString::c_str方法的具体用法?C++ CompString::c_str怎么用?C++ CompString::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompString
的用法示例。
在下文中一共展示了CompString::c_str方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fileNameWithExtension
bool
PngScreen::fileToImage (CompString &name,
CompSize &size,
int &stride,
void *&data)
{
bool status = false;
std::ifstream file;
CompString fileName = fileNameWithExtension (name);
file.open (fileName.c_str ());
if (file.is_open ())
{
status = readPng (file, size, data);
file.close ();
}
if (status)
{
stride = size.width () * 4;
return true;
}
return screen->fileToImage (name, size, stride, data);
}
示例2: readSvgToImage
bool
SvgScreen::fileToImage (CompString &path,
CompSize &size,
int &stride,
void *&data)
{
CompString fileName = path;
bool status = false;
int len = fileName.length ();
if (len < 4 || fileName.substr (len - 4, 4) != ".svg")
fileName += ".svg";
status = readSvgToImage (fileName.c_str (), size, data);
if (status)
{
stride = size.width () * 4;
return true;
}
status = screen->fileToImage (path, size, stride, data);
return status;
}
示例3: finiTexture
void
SvgWindow::setSvg (CompString &data,
decor_point_t p[2])
{
RsvgHandle *svg = NULL;
GError *error = NULL;
if (!gWindow)
return;
svg = rsvg_handle_new_from_data ((guint8 *) data.c_str (),
data.length (), &error);
if (source)
{
rsvg_handle_free (source->svg);
source->svg = svg;
}
else
{
source = new SvgSource;
if (source)
source->svg = svg;
}
if (source && source->svg)
{
source->p1 = p[0];
source->p2 = p[1];
source->svg = svg;
gWindow->glDrawSetEnabled (this, true);
rsvg_handle_get_dimensions (svg, &source->dimension);
updateSvgContext ();
}
else
{
if (svg)
rsvg_handle_free (svg);
if (source)
{
delete source;
source = NULL;
}
if (context)
{
finiTexture (context->texture[0]);
delete context;
context = NULL;
}
gWindow->glDrawSetEnabled (this, false);
}
}
示例4: get_format
CompString get_format (const CompString &fmt, Value::Ptr v)
{
if (fmt == "%i" || fmt == "%d")
return compPrintf(fmt.c_str(),
(boost::shared_static_cast<TValue<int> >(v))->value());
if (fmt == "%f")
return compPrintf(fmt.c_str(),
(boost::shared_static_cast<TValue<float> >(v))->value());
if (fmt == "%s")
return compPrintf(
fmt.c_str(),
(boost::shared_static_cast<TValue<std::string> >(v))->value().c_str());
if (fmt == "%x")
return compPrintf(fmt.c_str(),
(boost::shared_static_cast<TValue<int> >(v))->value());
return "not_reached";
}
示例5: CompString
/*
* File reader function
*/
CompString
FragmentParser::programReadSource (const CompString &fname)
{
std::ifstream fp;
int length;
char *buffer;
CompString data, path, home = CompString (getenv ("HOME"));
/* Try to open file fname as is */
fp.open (fname.c_str ());
/* If failed, try as user filter file (in ~/.compiz/data/filters) */
if (!fp.is_open () && !home.empty ())
{
path = home + "/.compiz/data/filters/" + fname;
fp.open (path.c_str ());
}
/* If failed again, try as system wide data file
* (in PREFIX/share/compiz/filters) */
if (!fp.is_open ())
{
path = CompString (DATADIR) + "/data/filters/" + fname;
fp.open (path.c_str ());
}
/* If failed again & again, abort */
if (!fp.is_open ())
{
return CompString ("");
}
/* get length of file: */
fp.seekg (0, std::ios::end);
length = fp.tellg ();
length++;
fp.seekg (0, std::ios::beg);
/* allocate memory */
buffer = new char [length];
/* read data as a block: */
fp.read (buffer, length - 1);
buffer[length - 1] = '\0';
fp.close ();
data = buffer;
delete[] buffer;
return data;
}
示例6: compileShader
static bool compileShader (GLuint *shader, GLenum type, CompString &source)
{
const GLchar *data;
GLint status;
data = (GLchar *)source.c_str ();
*shader = (*GL::createShader) (type);
(*GL::shaderSource) (*shader, 1, &data, NULL);
(*GL::compileShader) (*shader);
(*GL::getShaderiv) (*shader, GL::COMPILE_STATUS, &status);
return (status == GL_TRUE);
}
示例7: renderText
bool
CompText::renderWindowTitle (Window window,
bool withViewportNumber,
const CompText::Attrib &attrib)
{
CompString text;
TEXT_SCREEN (screen);
if (!ts)
return false;
if (withViewportNumber)
{
CompString title;
CompPoint winViewport;
CompSize viewportSize;
title = ts->getWindowName (window);
if (!title.empty ())
{
CompWindow *w;
w = screen->findWindow (window);
if (w)
{
int viewport;
winViewport = w->defaultViewport ();
viewportSize = screen->vpSize ();
viewport = winViewport.y () * viewportSize.width () +
winViewport.x () + 1;
text = compPrintf ("%s -[%d]-", title.c_str (), viewport);
}
else
{
text = title;
}
}
}
else
{
text = ts->getWindowName (window);
}
if (text.empty ())
return false;
return renderText (text, attrib);
}
示例8: programParseSource
/*
* Build a Compiz Fragment Function from a source string
*/
GLFragment::FunctionId
FragmentParser::buildFragmentProgram (CompString &source,
const CompString &name,
int target)
{
GLFragment::FunctionData *data;
int handle;
/* Create the function data */
data = new GLFragment::FunctionData ();
if (!data)
return 0;
/* Parse the source and fill the function data */
programParseSource (data, target, source);
/* Create the function */
handle = data->createFragmentFunction (name.c_str ());
delete data;
return handle;
}
示例9:
bool
CompOption::stringToColor (CompString color,
unsigned short *rgba)
{
int c[4];
if (sscanf (color.c_str (), "#%2x%2x%2x%2x",
&c[0], &c[1], &c[2], &c[3]) == 4)
{
rgba[0] = c[0] << 8 | c[0];
rgba[1] = c[1] << 8 | c[1];
rgba[2] = c[2] << 8 | c[2];
rgba[3] = c[3] << 8 | c[3];
return true;
}
return false;
}
示例10: foreach
int
BicubicScreen::getBicubicFragmentFunction (GLTexture *texture,
int param,
int unit)
{
GLFragment::FunctionData *data;
int target;
CompString targetString;
if (texture->target () == GL_TEXTURE_2D)
{
target = COMP_FETCH_TARGET_2D;
targetString = "2D";
}
else
{
target = COMP_FETCH_TARGET_RECT;
targetString = "RECT";
}
foreach (BicubicFunction *function, func)
if (function->param == param &&
function->target == target &&
function->unit == unit)
return function->handle;
data = new GLFragment::FunctionData ();
if (data)
{
int handle = 0;
BicubicFunction *function = NULL;
CompString filterTemp[] = {
"hgX", "hgY", "cs00", "cs01", "cs10", "cs11"
};
for (unsigned int i = 0; i < sizeof (filterTemp) / sizeof (filterTemp[0]); i++)
data->addTempHeaderOp (filterTemp[i].c_str());
data->addDataOp (
"MAD cs00, fragment.texcoord[0], program.env[%d],"
"{-0.5, -0.5, 0.0, 0.0};", param + 2);
data->addDataOp (
"TEX hgX, cs00.x, texture[%d], 1D;", unit);
data->addDataOp (
"TEX hgY, cs00.y, texture[%d], 1D;", unit);
data->addDataOp (
"MUL cs10, program.env[%d], hgX.y;", param);
data->addDataOp (
"MUL cs00, program.env[%d], -hgX.x;", param);
data->addDataOp (
"MAD cs11, program.env[%d], hgY.y, cs10;", param + 1);
data->addDataOp (
"MAD cs01, program.env[%d], hgY.y, cs00;", param + 1);
data->addDataOp (
"MAD cs10, program.env[%d], -hgY.x, cs10;", param + 1);
data->addDataOp (
"MAD cs00, program.env[%d], -hgY.x, cs00;", param + 1);
data->addDataOp (
"ADD cs00, cs00, fragment.texcoord[0];");
data->addDataOp (
"ADD cs01, cs01, fragment.texcoord[0];");
data->addDataOp (
"ADD cs10, cs10, fragment.texcoord[0];");
data->addDataOp (
"ADD cs11, cs11, fragment.texcoord[0];");
data->addDataOp (
"TEX cs00, cs00, texture[0], %s;", targetString.c_str());
data->addDataOp (
"TEX cs01, cs01, texture[0], %s;", targetString.c_str());
data->addDataOp (
"TEX cs10, cs10, texture[0], %s;", targetString.c_str());
data->addDataOp (
"TEX cs11, cs11, texture[0], %s;", targetString.c_str());
data->addDataOp ( "LRP cs00, hgY.z, cs00, cs01;");
data->addDataOp ( "LRP cs10, hgY.z, cs10, cs11;");
data->addDataOp ( "LRP output, hgX.z, cs00, cs10;");
data->addColorOp ( "output", "output");
if (!data->status ())
{
delete data;
return 0;
}
function = new BicubicFunction ();
if (function)
{
handle = data->createFragmentFunction ("bicubic");
function->handle = handle;
function->target = target;
function->param = param;
//.........这里部分代码省略.........
示例11: XInternAtom
PropertyWriter::PropertyWriter (CompString propName,
CompOption::Vector &readTemplate)
{
mPropertyValues = readTemplate;
mAtom = XInternAtom (screen->dpy (), propName.c_str (), 0);
}
示例12: MIN
bool
TextSurface::render (const CompText::Attrib &attrib,
const CompString &text)
{
int width, height, layoutWidth;
if (!valid ())
return false;
pango_font_description_set_family (font, attrib.family);
pango_font_description_set_absolute_size (font,
attrib.size * PANGO_SCALE);
pango_font_description_set_style (font, PANGO_STYLE_NORMAL);
if (attrib.flags & CompText::StyleBold)
pango_font_description_set_weight (font, PANGO_WEIGHT_BOLD);
if (attrib.flags & CompText::StyleItalic)
pango_font_description_set_style (font, PANGO_STYLE_ITALIC);
pango_layout_set_font_description (layout, font);
if (attrib.flags & CompText::Ellipsized)
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
pango_layout_set_auto_dir (layout, false);
pango_layout_set_text (layout, text.c_str (), -1);
pango_layout_get_pixel_size (layout, &width, &height);
if (attrib.flags & CompText::WithBackground)
{
width += 2 * attrib.bgHMargin;
height += 2 * attrib.bgVMargin;
}
width = MIN (attrib.maxWidth, width);
height = MIN (attrib.maxHeight, height);
/* update the size of the pango layout */
layoutWidth = attrib.maxWidth;
if (attrib.flags & CompText::WithBackground)
layoutWidth -= 2 * attrib.bgHMargin;
pango_layout_set_width (layout, layoutWidth * PANGO_SCALE);
if (!update (width, height))
return false;
pango_cairo_update_layout (cr, layout);
cairo_save (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_restore (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
if (attrib.flags & CompText::WithBackground)
{
drawBackground (0, 0, width, height,
MIN (attrib.bgHMargin, attrib.bgVMargin));
cairo_set_source_rgba (cr,
attrib.bgColor[0] / 65535.0,
attrib.bgColor[1] / 65535.0,
attrib.bgColor[2] / 65535.0,
attrib.bgColor[3] / 65535.0);
cairo_fill (cr);
cairo_move_to (cr, attrib.bgHMargin, attrib.bgVMargin);
}
cairo_set_source_rgba (cr,
attrib.color[0] / 65535.0,
attrib.color[1] / 65535.0,
attrib.color[2] / 65535.0,
attrib.color[3] / 65535.0);
pango_cairo_show_layout (cr, layout);
return true;
}
示例13: if
/*
* Parse the source buffer op by op and add each op to function data
*
* FIXME : I am more than 200 lines long, I feel so heavy!
*/
void
FragmentParser::programParseSource (GLFragment::FunctionData *data,
int target, CompString &source)
{
CompString line, next;
CompString current;
CompString strtok;
size_t pos = 0, strippos = 0;
int length, oplength, type;
CompString arg1, arg2, temp;
/* Find the header, skip it, and start parsing from there */
pos = source.find ("!!ARBfp1.0", pos);
if (pos != std::string::npos)
{
pos += 9;
}
/* Strip comments */
while ((strippos = source.find ("#", strippos)) != std::string::npos)
{
size_t carriagepos = source.find ("\n", strippos);
if (carriagepos != std::string::npos)
{
source.erase (strippos, carriagepos - strippos);
strippos = 0;
}
else
source = source.substr (0, strippos);
}
strippos = 0;
/* Strip linefeeds */
while ((strippos = source.find ("\n", strippos)) != std::string::npos)
source[strippos] = ' ';
/* Parse each instruction */
while (!(pos >= (source.size () - 1)))
{
size_t nPos = source.find (";", pos + 1);
line = source.substr (pos + 1, nPos - pos);
CompString origcurrent = current = ltrim (line);
/* Find instruction type */
type = NoOp;
/* Data ops */
if (current.substr (0, 3) == "END")
type = NoOp;
else if (current.substr (0, 3) == "ABS" ||
current.substr (0, 3) == "CMP" ||
current.substr (0, 3) == "COS" ||
current.substr (0, 3) == "DP3" ||
current.substr (0, 3) == "DP4" ||
current.substr (0, 3) == "EX2" ||
current.substr (0, 3) == "FLR" ||
current.substr (0, 3) == "FRC" ||
current.substr (0, 3) == "KIL" ||
current.substr (0, 3) == "LG2" ||
current.substr (0, 3) == "LIT" ||
current.substr (0, 3) == "LRP" ||
current.substr (0, 3) == "MAD" ||
current.substr (0, 3) == "MAX" ||
current.substr (0, 3) == "MIN" ||
current.substr (0, 3) == "POW" ||
current.substr (0, 3) == "RCP" ||
current.substr (0, 3) == "RSQ" ||
current.substr (0, 3) == "SCS" ||
current.substr (0, 3) == "SIN" ||
current.substr (0, 3) == "SGE" ||
current.substr (0, 3) == "SLT" ||
current.substr (0, 3) == "SUB" ||
current.substr (0, 3) == "SWZ" ||
current.substr (0, 3) == "TXP" ||
current.substr (0, 3) == "TXB" ||
current.substr (0, 3) == "XPD")
type = DataOp;
else if (current.substr (0, 4) == "TEMP")
type = TempOp;
else if (current.substr (0, 5) == "PARAM")
type = ParamOp;
else if (current.substr (0, 6) == "ATTRIB")
type = AttribOp;
else if (current.substr (0, 3) == "TEX")
type = FetchOp;
else if (current.substr (0, 3) == "ADD")
{
if (current.find ("fragment.texcoord", 0) != std::string::npos)
programAddOffsetFromAddOp (current.c_str ());
else
type = DataOp;
}
//.........这里部分代码省略.........
示例14: compLogMessage
static bool
dlloaderLoadPlugin (CompPlugin *p,
const char *path,
const char *name)
{
CompString file;
void *dlhand;
bool loaded = false;
if (cloaderLoadPlugin (p, path, name))
return true;
if (path)
{
file = path;
file += "/";
}
file += "lib";
file += name;
file += ".so";
compLogMessage (here, CompLogLevelDebug,
"Trying to load %s from: %s", name, file.c_str ());
int open_flags = RTLD_NOW;
#ifdef DEBUG
// Do not unload the library during dlclose.
open_flags |= RTLD_NODELETE;
// Make the symbols available globally
open_flags |= RTLD_GLOBAL;
#endif
dlhand = dlopen (file.c_str (), open_flags);
if (dlhand)
{
PluginGetInfoProc getInfo;
char *error;
char sym[1024];
compLogMessage (here, CompLogLevelDebug,
"Opened library: %s", file.c_str ());
dlerror ();
snprintf (sym, 1024, "getCompPluginVTable20090315_%s", name);
getInfo = (PluginGetInfoProc) dlsym (dlhand, sym);
error = dlerror ();
if (error)
{
compLogMessage (here, CompLogLevelError, "dlsym: %s", error);
getInfo = 0;
}
if (getInfo)
{
p->vTable = (*getInfo) ();
if (!p->vTable)
{
compLogMessage (here, CompLogLevelError,
"Couldn't get vtable from '%s' plugin",
file.c_str ());
}
else
{
p->devPrivate.ptr = dlhand;
p->devType = "dlloader";
loaded = true;
compLogMessage (here, CompLogLevelDebug,
"Loaded plugin %s from: %s",
name, file.c_str ());
}
}
}
else
{
compLogMessage (here, CompLogLevelDebug,
"dlopen failed: %s", dlerror ());
}
if (!loaded && dlhand)
dlclose (dlhand);
return loaded;
}