本文整理汇总了C++中TStr::CStr方法的典型用法代码示例。如果您正苦于以下问题:C++ TStr::CStr方法的具体用法?C++ TStr::CStr怎么用?C++ TStr::CStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStr
的用法示例。
在下文中一共展示了TStr::CStr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveSS
void TTable::SaveSS(const TStr& OutFNm){
FILE* F = fopen(OutFNm.CStr(), "w");
// debug
if(F == NULL){
printf("failed to open file %s\n", OutFNm.CStr());
perror("fail ");
return;
}
TInt L = S.Len();
// print title (schema)
for(TInt i = 0; i < L-1; i++){
fprintf(F, "%s\t", GetSchemaColName(i).CStr());
}
fprintf(F, "%s\n", GetSchemaColName(L-1).CStr());
// print table contents
for(TRowIterator RowI = BegRI(); RowI < EndRI(); RowI++){
for(TInt i = 0; i < L; i++){
char C = (i == L-1) ? '\n' : '\t';
switch(GetSchemaColType(i)){
case INT:{
fprintf(F, "%d%c", RowI.GetIntAttr(GetSchemaColName(i)).Val, C);
break;
}
case FLT:{
fprintf(F, "%f%c", RowI.GetFltAttr(GetSchemaColName(i)).Val, C);
break;
}
case STR:{
fprintf(F, "%s%c", RowI.GetStrAttr(GetSchemaColName(i)).CStr(), C);
break;
}
}
}
}
fclose(F);
}
示例2: main
int main(int argc, char* argv[]) {
Env = TEnv(argc, argv, TNotify::StdNotify);
Env.PrepArgs(TStr::Fmt("Clique Percolation Method. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
TExeTm ExeTm;
Try
const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt", "Input undirected graph file (single directed edge per line)");
const int OverlapSz = Env.GetIfArgPrefixInt("-k:", 2, "Min clique overlap");
TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "Output file prefix");
if (OutFNm.Empty()) { OutFNm = InFNm.GetFMid(); }
PUNGraph G;
if (InFNm == "DEMO") { // small demo graph
G = TUNGraph::New();
for (int i = 1; i < 8; i++) { G->AddNode(i); }
G->AddEdge(1,2);
G->AddEdge(2,3); G->AddEdge(2,4);
G->AddEdge(3,4);
G->AddEdge(4,5); G->AddEdge(4,7);
G->AddEdge(5,6); G->AddEdge(5,7);
G->AddEdge(6,7);
// draw the small graph using GraphViz
TSnap::DrawGViz(G, gvlNeato, "small_graph.png", "", true);
}
// load graph
else if (InFNm.GetFExt().GetLc()==".ungraph") {
TFIn FIn(InFNm); G=TUNGraph::Load(FIn); }
else if (InFNm.GetFExt().GetLc()==".ngraph") {
TFIn FIn(InFNm); G=TSnap::ConvertGraph<PUNGraph>(TNGraph::Load(FIn), false); }
else {
G = TSnap::LoadEdgeList<PUNGraph>(InFNm, 0, 1); }
// find communities
TVec<TIntV> CmtyV;
TCliqueOverlap::GetCPMCommunities(G, OverlapSz+1, CmtyV);
// save result
FILE *F = fopen(TStr::Fmt("cpm-%s.txt", OutFNm.CStr()).CStr(), "wt");
fprintf(F, "# %d Overlapping Clique Percolation Communities (min clique overlap %d)\n", CmtyV.Len(), OverlapSz);
fprintf(F, "# Each line contains nodes belonging to the same community community\n");
for (int i = 0; i < CmtyV.Len(); i++) {
fprintf(F, "%d", CmtyV[i][0].Val);
for (int j = 1; j < CmtyV[i].Len(); j++) {
fprintf(F, "\t%d", CmtyV[i][j].Val);
}
fprintf(F, "\n");
}
Catch
printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
return 0;
}
示例3: OnActExtEdBtClick
void __fastcall TVclStrGrid::OnActExtEdBtClick(TObject *Sender){
TStr ExtNm=ActExtEdBt->Caption.c_str();
TExtGetStrF ExtGetStrF;
if (IsExtGetStrF(ExtNm, ExtGetStrF)){
int ColN; int RowN;
if (IsSelCell(ColN, RowN)){
TStr PrevValStr=GetVal(ColN, RowN);
TStr NewValStr; bool OkP;
(*ExtGetStrF())(false, PrevValStr, NewValStr, OkP);
if (OkP){
ActExtValEd->Text=NewValStr.CStr();
}
}
}
}
示例4: GetIfArgPrefixFlt
double TEnv::GetIfArgPrefixFlt(
const TStr& PrefixStr, const double& DfVal, const TStr& DNm) const {
if (Env.GetArgs()<=MnArgs) {
// 'usage' argument message
if (!SilentP) {
printf(" %s%s (default:%g)\n", PrefixStr.CStr(), DNm.CStr(), DfVal);
}
return DfVal;
} else {
// argument & value message
double Val;
if (Env.IsArgPrefix(PrefixStr)) {
TStr ValStr=Env.GetArgPostfix(PrefixStr);
Val=ValStr.GetFlt(DfVal);
} else {
Val=DfVal;
}
TStr MsgStr=DNm+" ("+PrefixStr+")="+TFlt::GetStr(Val);
if (!SilentP) {
TNotify::OnStatus(Notify, MsgStr);
}
return Val;
}
}
示例5: SaveGViz
void TGraphKey::SaveGViz(const TStr& OutFNm, const TStr& Desc, const TStr& NodeAttrs, const int& Size) const {
FILE *F = fopen(OutFNm.CStr(), "wt");
fprintf(F, "/*****\n");
fprintf(F, " Graph (%d, %d)\n", GetNodes(), GetEdges());
//if (! Desc.Empty()) fprintf(F, " %s\n", Desc.CStr());
fprintf(F, "*****/\n\n");
fprintf(F, "digraph G {\n");
if (Size != -1) fprintf(F, " size=\"%d,%d\";\n", Size, Size);
fprintf(F, " graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
if (NodeAttrs.Empty()) fprintf(F, " node [shape=ellipse, width=0.3, height=0.3]\n");
else fprintf(F, " node [shape=ellipse, %s]\n", NodeAttrs.CStr());
if (! EdgeV.Empty()) {
for (int e = 0; e < EdgeV.Len(); e++) {
fprintf(F, " %d -> %d;\n", EdgeV[e].Val1(), EdgeV[e].Val2()); }
} else {
for (int n = 0; n < Nodes; n++) { fprintf(F, " %d;\n", n); }
}
if (! Desc.Empty()) {
fprintf(F, " label = \"\\n%s\\n\";", Desc.CStr());
fprintf(F, " fontsize=24;\n");
}
fprintf(F, "}\n");
fclose(F);
}
示例6: Plot
void TGStat::Plot(const TGStatDistr& Distr, const TStr& FNmPref, TStr Desc, bool PowerFit) const {
if (Desc.Empty()) Desc = FNmPref.GetUc();
if (! HasDistr(Distr) || Distr==gsdUndef || Distr==gsdMx) { return; }
TPlotInfo Info = GetPlotInfo(Distr);
TGnuPlot GnuPlot(Info.Val1+TStr(".")+FNmPref, TStr::Fmt("%s. G(%d, %d)", Desc.CStr(), GetNodes(),GetEdges()));
GnuPlot.SetXYLabel(Info.Val2, Info.Val3);
GnuPlot.SetScale(Info.Val4);
const int plotId = GnuPlot.AddPlot(GetDistr(Distr), gpwLinesPoints, "");
if (PowerFit) { GnuPlot.AddPwrFit(plotId, gpwLines); }
#ifdef GLib_MACOSX
GnuPlot.SaveEps();
#else
GnuPlot.SavePng();
#endif
}
示例7:
TEST(TNEANet, GetSAttrNameE) {
PNEANet Graph;
Graph = TNEANet::New();
TInt AttrId;
Graph->AddSAttrE("TestInt", atInt, AttrId);
Graph->AddSAttrE("TestFlt", atFlt, AttrId);
Graph->AddSAttrE("TestStr", atStr, AttrId);
TAttrType AttrType;
TStr Name;
int status = Graph->GetSAttrNameE(0, Name, AttrType);
EXPECT_EQ(0, status);
EXPECT_EQ(atInt, AttrType);
EXPECT_STREQ("TestInt", Name.CStr());
status = Graph->GetSAttrNameE(1, Name, AttrType);
EXPECT_EQ(0, status);
EXPECT_EQ(atFlt, AttrType);
EXPECT_STREQ("TestFlt", Name.CStr());
status = Graph->GetSAttrNameE(2, Name, AttrType);
EXPECT_EQ(0, status);
EXPECT_EQ(atStr, AttrType);
EXPECT_STREQ("TestStr", Name.CStr());
status = Graph->GetSAttrNameE(3, Name, AttrType);
EXPECT_EQ(-1, status);
}
示例8: SavePajek
void TNetInfBs::SavePajek(const TStr& OutFNm) {
TIntSet NIdSet;
FILE *F = fopen(OutFNm.CStr(), "wt");
fprintf(F, "*Vertices %d\r\n", NIdSet.Len());
for (THash<TInt, TNodeInfo>::TIter NI = NodeNmH.BegI(); NI < NodeNmH.EndI(); NI++) {
const TNodeInfo& I = NI.GetDat();
fprintf(F, "%d \"%s\" ic Blue x_fact %f y_fact %f\r\n", NI.GetKey().Val,
I.Name.CStr(), TMath::Mx<double>(log((double)I.Vol)-5,1), TMath::Mx<double>(log((double)I.Vol)-5,1));
}
fprintf(F, "*Arcs\r\n");
for (TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
fprintf(F, "%d %d 1\r\n", EI.GetSrcNId(), EI.GetDstNId());
}
fclose(F);
}
示例9: TSBase
TZipIn::TZipIn(const TStr& FNm) : TSBase(FNm.CStr()), TSIn(FNm), ZipStdoutRd(NULL), ZipStdoutWr(NULL),
FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
EAssertR(! FNm.Empty(), "Empty file-name.");
EAssertR(TFile::Exists(FNm), TStr::Fmt("File %s does not exist", FNm.CStr()).CStr());
FLen = TZipIn::GetFLen(FNm);
if (FLen == 0) { return; } // empty file
#ifdef GLib_WIN
// create pipes
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
// Create a pipe for the child process's STDOUT.
const int PipeBufferSz = 32*1024;
EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed");
// Ensure the read handle to the pipe for STDOUT is not inherited.
SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
#else
// no implementation needed
#endif
CreateZipProcess(GetCmd(FNm), FNm);
Bf = new char[MxBfL]; BfC = BfL=-1;
FillBf();
}
示例10: SavePlaneTextNet
void TNetInfBs::SavePlaneTextNet(const TStr& OutFNm) {
TIntSet NIdSet;
FILE *F = fopen(OutFNm.CStr(), "wt");
for (THash<TInt, TNodeInfo>::TIter NI = NodeNmH.BegI(); NI < NodeNmH.EndI(); NI++) {
const TNodeInfo& I = NI.GetDat();
fprintf(F, "%d,%d\r\n", NI.GetKey().Val, NI.GetKey().Val);
}
fprintf(F, "\r\n");
for (TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
fprintf(F, "%d,%d\r\n", EI.GetSrcNId(), EI.GetDstNId());
}
fclose(F);
}
示例11: DumpCmtyVV
/// dump bipartite community affiliation into a text file with node names
void TAGMUtil::DumpCmtyVV(const TStr OutFNm, TVec<TIntV>& CmtyVV, TIntStrH& NIDNmH) {
FILE* F = fopen(OutFNm.CStr(), "wt");
for (int c = 0; c < CmtyVV.Len(); c++) {
for (int u = 0; u < CmtyVV[c].Len(); u++) {
if (NIDNmH.IsKey(CmtyVV[c][u])) {
fprintf(F, "%s\t", NIDNmH.GetDat(CmtyVV[c][u]).CStr());
}
else {
fprintf(F, "%d\t", (int) CmtyVV[c][u]);
}
}
fprintf(F, "\n");
}
fclose(F);
}
示例12: main
int main(int argc, char *argv[]) {
TDocBase *DocBase = new TDocBase;
TChA Url = TChA("http://www.newyorktimes.com/news_story");
TSecTm Date = TSecTm::GetCurTm();
TChA Content = TChA("foo bar foo foo");
TVec<TChA> Links;
Links.Add(TChA("http://www.google.com"));
Links.Add(TChA("http://www.yahoo.com"));
DocBase->AddDoc(Url, Date, Content, Links);
printf("Number of documents: %d\n", DocBase->Len());
TDoc t;
DocBase->GetDoc(0, t);
TStr tUrl;
t.GetUrl(tUrl);
printf("URL: %s\n", tUrl.CStr());
TStrV l;
t.GetLinks(l);
printf("Link1: %s\n", l[0].CStr());
printf("Link2: %s\n", l[1].CStr());
{ TFOut FOut("tmp.bin"); DocBase->Save(FOut); }
printf("Save data successfully\n");
delete DocBase;
TFIn FIn("tmp.bin");
printf("Load data successfully\n");
TDocBase *DocBase2 = new TDocBase;
DocBase2->Load(FIn);
printf("Number of documents: %d\n", DocBase2->Len());
TDoc t2;
DocBase2->GetDoc(0, t2);
TStr t2Url;
t2.GetUrl(t2Url);
printf("URL: %s\n", t2Url.CStr());
t2.GetLinks(l);
printf("Link1: %s\n", l[0].CStr());
printf("Link2: %s\n", l[1].CStr());
delete DocBase2;
return 0;
}
示例13: InitHt
void InitHt(Handle<Object> Exports, const TStr& NsNm) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
Handle<Object> NsObj = Object::New(Isolate);
TNodeJsStrStrH::Init(NsObj);
TNodeJsStrIntH::Init(NsObj);
TNodeJsStrFltH::Init(NsObj);
TNodeJsIntStrH::Init(NsObj);
TNodeJsIntIntH::Init(NsObj);
TNodeJsIntFltH::Init(NsObj);
Exports->Set(String::NewFromUtf8(Isolate, NsNm.CStr()), NsObj);
}
示例14: HandleScope
v8::Local<v8::Object> TNodeJsFIn::New(const TStr& FNm) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope HandleScope(Isolate);
v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(Isolate, constructor);
v8::Local<v8::Value> ArgFNm = v8::String::NewFromUtf8(Isolate, FNm.CStr());
// Pass file path as argument to New
const int Argc = 1;
v8::Local<v8::Value> Argv[Argc] = { ArgFNm };
v8::Local<v8::Object> Instance = cons->NewInstance(Argc, Argv);
TNodeJsFIn* JsFIn = new TNodeJsFIn(FNm);
JsFIn->Wrap(Instance);
return HandleScope.Escape(Instance);
}
示例15: GetAsyncSockHost
void TSockSys::GetAsyncSockHost(const TStr& HostNm, const PSockHost& SockHost) {
// prepare address info request
uv_getaddrinfo_t* Request = (uv_getaddrinfo_t*)malloc(sizeof(uv_getaddrinfo_t));
// submit the request
int ResCd = uv_getaddrinfo(Loop, Request, TSockSys::OnGetHost, HostNm.CStr(), NULL, NULL);
// check submission went fine
if (ResCd != 0) {
// cleanup first
free(Request);
// and throw exception
throw TExcept::New("TSockSys.GetAsyncSockHost: Error requestiong resolve of hostname " + HostNm);
}
// remember SockHost for the callback
TUInt64 RequestHnd = (uint64)Request;
HndToSockHostH.AddDat(RequestHnd, SockHost);
}