本文整理汇总了C++中Filename类的典型用法代码示例。如果您正苦于以下问题:C++ Filename类的具体用法?C++ Filename怎么用?C++ Filename使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filename类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
void File::open(const Filename &filepath, const char *mode) {
// Clean up previously opened file
close();
_file = fopen(filepath.getFullPath().c_str(), mode);
if (!_file) {
std::string fixedPath = fixPathCase(filepath.getFullPath());
_file = fopen(fixedPath.c_str(), mode);
}
FileMode m = FILEMODE_READ;
do {
switch(*mode) {
case 'w': m = FILEMODE_WRITE; break;
case 'r': m = FILEMODE_READ; break;
case 'b': m = FileMode(m | FILEMODE_BINARY); break;
case '+': m = FileMode(m | FILEMODE_READ | FILEMODE_WRITE); break;
default: throw FileException(std::string("Unsupported FileMode ") + mode);
}
} while (*++mode);
_mode = m;
_name = filepath;
_xormode = 0;
if (!_file)
throw FileException("Could not open file " + filepath.getFullPath());
}
示例2:
void Compartment_Report_HDF5_File_Reader::open_data_set
(Cell_GID cell_ID, const char * dataset_name, H5ID & file, H5ID & dataset) const
{
// Opening file for current cell
std::string cell_name = "a" + boost::lexical_cast<std::string>(cell_ID);
Filename filename = _path / (cell_name + ".h5");
file.reset(H5Fopen(filename.string().c_str(), H5F_ACC_RDONLY, H5P_DEFAULT),
H5Fclose);
if (!file)
{
throw_exception(
File_Open_Error("Compartment_Report_HDF5_File_Reader: error "
"opening file:" + filename.string()),
FATAL_LEVEL, __FILE__, __LINE__);
}
// Opening the dataset
std::string dataset_full_name =
"/" + cell_name + "/" + (_report_name + "/") + dataset_name;
H5E_BEGIN_TRY
dataset.reset(H5Dopen(file, dataset_full_name.c_str()), H5Dclose);
H5E_END_TRY;
if (!dataset)
{
throw_exception(
File_Parse_Error("Compartment_Report_HDF5_File_Reader: "
"Dataset " + dataset_full_name + " not found "
"in file: " + filename.string()),
FATAL_LEVEL, __FILE__, __LINE__);
}
}
示例3: SaveResult
/*********************************************************************\
Function name : CCompareTableDialog::SaveResult
Description :
Created at : 10.10.01, @ 22:16:07
Created by : Thomas Kunert
Modified by :
\*********************************************************************/
void CCompareTableDialog::SaveResult()
{
Filename fn;
if (!fn.FileSelect(FILESELECTTYPE_ANYTHING, FILESELECT_SAVE, String())) return;
Int32 lMaxLen = 0;
Int32 a, lNumItems;
lNumItems = m_wndOutputList.GetItemCount();
for (a = 0; a < lNumItems; a++)
{
BaseContainer data;
m_wndOutputList.GetItem(a, &data);
lMaxLen = LMax(lMaxLen, data.GetString(COMPARE_LIST_NAME).GetLength());
}
lMaxLen += 2;
AutoAlloc <BaseFile> pFile;
if (!pFile)
return;
pFile->Open(fn, FILEOPEN_WRITE);
for (a = 0; a < lNumItems; a++)
{
BaseContainer data;
m_wndOutputList.GetItem(a, &data);
String str = data.GetString(COMPARE_LIST_NAME);
WriteString(pFile, str);
Int32 b = lMaxLen - str.GetLength();
while (b--) WriteString(pFile, " ");
WriteString(pFile, data.GetString(COMPARE_LIST_DATA));
LineBreak(pFile, "");
}
}
示例4: load_from_file
void Level::load_from_file(const Filename& filename)
{
clear();
status = GOOD;
level_filename = filename.get_rootless();
FileFormat fmt = get_file_format(filename);
if (fmt == FORMAT_BINARY) {
// load an original .LVL file from L1/ONML/...
load_from_binary(filename);
}
else if (fmt == FORMAT_LEMMINI) {
// load an .INI file from Lemmini
load_from_lemmini(filename);
}
else {
// load the regular Lix format
std::vector <IO::Line> lines;
if (IO::fill_vector_from_file(lines, filename.get_rootful())) {
load_from_vector(lines);
}
else status = BAD_FILE_NOT_FOUND;
}
load_finalize();
}
示例5: IsisMain
void IsisMain() {
UserInterface &ui = Application::GetUserInterface();
bool append = ui.GetBoolean("APPEND");
Pvl input (ui.GetFilename("FROM"));
Pvl output;
// Check to see if output file exists
Filename outFile = ui.GetFilename("TO");
if (outFile.exists()&&!append) {
string msg = "Output file [" + outFile.Expanded() + "] already exists.";
msg += " Append option set to False.";
throw iException::Message(iException::User,msg,_FILEINFO_);
}
int numErrors = 0;
// Search for errors and add to output
for (int i =0; i < input.Objects(); i++) {
PvlObject o = input.Object(i);
if (o.HasGroup("Error")) {
output.AddObject(o);
numErrors++;
}
}
PvlKeyword errors("TotalErrors",numErrors);
output.AddKeyword(errors);
// write output to file
if (!append) {
output.Write(outFile.Expanded());
} else {
output.Append(outFile.Expanded());
}
cout << errors << endl;
}
示例6: GetBool
void ApplinkDialog::Timer(const BaseContainer &msg)
{
Bool b;
GetBool(IDC_CHK_PROMPT, b);
if(b)
{
Filename fn;
fn.SetDirectory(gPreferences.GetString(IDC_EXCH_FOLDER));
fn.SetFile("export.txt");
if(GeFExist(fn))
{
GePrint("File exists!");
SetTimer(0);
if(GeOutString("To import a new object?", GEMB_OKCANCEL) == GEMB_R_OK)
{
GePrint("Start import!");
BaseDocument* doc = GetActiveDocument();
ApplinkImporter* importer = NewObjClear(ApplinkImporter);
importer->Execute(doc, &gPreferences);
SetTimer(1000);
}
else
{
SetBool(IDC_CHK_PROMPT, false);
}
}
}
}
示例7: main
/**
* Program entry point.
*/
int main(int argc, char *argv[ ])
{
SetupSharedThread::install();
SetupSharedDebug::install(4096);
{
SetupSharedFoundation::Data data(SetupSharedFoundation::Data::D_console);
#ifdef WIN32
char buffer[1024];
GetModuleFileName(GetModuleHandle(NULL), buffer, 1024);
Filename configName;
configName.setName(buffer);
configName.setName("templateCompiler.cfg");
data.configFile = configName.getFullFilename().c_str();
#endif
SetupSharedFoundation::install (data);
}
SetupSharedRegex::install();
SetupSharedCompression::install();
SetupSharedFile::install(false);
// setup the random number generator
// @todo need a better seed
SetupSharedRandom::install(static_cast<uint32>(time(NULL)));
int result = processArgs(argc, argv);
// cleanup
SetupSharedFoundation::remove();
PerThreadData::threadRemove();
return result;
} // main
示例8: get_file_format
Level::FileFormat Level::get_file_format(const Filename& filename)
{
if (! ::exists(filename.get_rootful().c_str())) return FORMAT_NOTHING;
std::ifstream file(filename.get_rootful().c_str(), std::ios::binary);
// the length check before the read() was necessary for me on Linux
// to get the Debugger past this, it got stuck on read() when nothing
// was wrong.
file.seekg (0, std::ios::end);
if (file.tellg() < 8) {
file.close();
return FORMAT_NOTHING;
}
file.seekg(0, std::ios::beg);
unsigned char buf[8];
file.read((char*) &buf, 8);
file.close();
// A binary file has two-byte numbers in big endian
// for rate, lixes, required, seconds at the beginning.
// Neither should be > 0x00FF. If all of them are,
// this is an ASCII file which shouldn't have '\0' chars.
if (buf[0] == '\0' || buf[2] == '\0' || buf[4] == '\0' || buf[6] == '\0')
return FORMAT_BINARY;
// This isn't a binary file. Is it a Lemmini file?
// Lemmini files start with "# LVL".
else if (buf[0] == '#' && buf[1] == ' ' && buf[2] == 'L' && buf[3] == 'V')
return FORMAT_LEMMINI;
else return FORMAT_LIX;
}
示例9: getParameterVector
void ApplinkExporter::ExportChannel(BaseDocument* document, BaseFile* file, BaseMaterial& material, LONG shaderId, LONG colorId, const String s)
{
String str = s + " ";
// get texture strength and base colour
Vector color = getParameterVector(material, colorId);
str += RealToString(color.x, NULL, 6) + " " + RealToString(color.y, NULL, 6) + " " + RealToString(color.z, NULL, 6) + "\n";
this->WriteString(str, file);
// fetch bitmap shader, if available
BaseList2D* bitmapLink = ApplinkExporter::getParameterLink(material, shaderId, Xbitmap);
if(bitmapLink)
{
// if we are here, we've got a bitmap shader -> let's create an imagemap texture
Filename bitmapPath = ApplinkExporter::getParameterFilename(*bitmapLink, BITMAPSHADER_FILENAME);
Filename fullBitmapPath;
GenerateTexturePath(document->GetDocumentPath(), bitmapPath, Filename(), &fullBitmapPath);
str = "map_" + s + " ";
str += fullBitmapPath.GetString() + "\n";
this->WriteString(str, file);
}
}
示例10: processArgs
/**
* Processes the args sent to main.
*/
int processArgs(int argc, char *argv[ ])
{
if (argc < 3)
{
printSyntax();
return 0;
}
//if (strcmp(argv[1], "-edit") == 0)
//{
// for (int i = 2; i < argc; ++i)
// {
// int result = checkOut(argv[i]);
// if (result != 0)
// return result;
// }
//}
//else if (strcmp(argv[1], "-submit") == 0)
//{
// for (int i = 2; i < argc; ++i)
// {
// int result = checkIn(argv[i]);
// if (result != 0)
// return result;
// }
//}
if (strcmp(argv[1], "-compile") == 0)
{
Filename filename;
for (int i = 2; i < argc; ++i)
{
File::setBasePath("");
filename.clear();
filename.setExtension(TEMPLATE_DEFINITION_EXTENSION);
filename.setName(argv[i]);
File fp(filename, "rt");
if (!fp.isOpened())
{
fprintf(stderr, "cannot open file %s\n", argv[i]);
return -1;
}
else
{
File::setBasePath(filename.getPath().c_str());
int result = parseTemplateDefinitionFile(fp);
fp.close();
if (result != 0)
return result;
}
}
}
else
{
printSyntax();
return 0;
}
return 0;
} // processArgs
示例11: GeGetStartupPath
/*********************************************************************\
Function name : CLanguageList::Init
Description :
Created at : 26.09.01, @ 16:11:23
Created by : Thomas Kunert
Modified by :
\*********************************************************************/
void CLanguageList::Init()
{
Filename resourcepath = GeGetStartupPath() + Filename("resource");
if (GetC4DVersion() >= 16000) {
// R16 has a new resource directory structure. The c4d_language.str
// files we are searching for are in resource/modules/c4dplugin/strings_xx.
// Fix for https://github.com/nr-plugins/resedit/issues/4
resourcepath = resourcepath + "modules" + "c4dplugin";
}
AutoAlloc <BrowseFiles> pBrowse;
pBrowse->Init(resourcepath, false);
while (pBrowse->GetNext())
{
if (pBrowse->IsDir())
{
Filename fn = pBrowse->GetFilename();
if (fn.GetString().SubStr(0, 8).ToLower() == "strings_")
{
String idx = fn.GetString();
idx.Delete(0, 8);
Filename stringname = resourcepath + fn+Filename("c4d_language.str");
AutoAlloc <BaseFile> pFile;
if (!pFile)
return;
if (!GeFExist(stringname))
{
GeOutString("Missing c4d_language.str to identify the string directory!!!", GEMB_ICONEXCLAMATION);
}
else if (pFile->Open(stringname))
{
Int32 len = pFile->GetLength();
Char *buffer = NewMemClear(Char,len + 2);
if (buffer)
{
pFile->ReadBytes(buffer,len);
buffer[len]=0;
Int32 i;
for (i = 0; i < len && buffer[i] >= ' '; i++) { }
buffer[i] = 0;
for (i--; i > 0 && buffer[i]== ' '; i--) { }
buffer[i + 1] = 0;
AddLanguage(buffer, idx);
DeleteMem(buffer);
}
}
}
}
}
CriticalAssert(GetNumLanguages() > 0);
}
示例12: WriteMatsFile
Bool ApplinkExporter::WriteMatsFile(BaseDocument* document, BaseContainer* bc)
{
Filename filenameMTL;
filenameMTL.SetDirectory(bc->GetString(IDC_TMP_FOLDER));
filenameMTL.SetFile(document->GetDocumentName());
filenameMTL.SetSuffix("mtl");
GePrint(filenameMTL.GetString());
AutoAlloc<BaseFile> fileMTL;
if (!fileMTL->Open(filenameMTL, FILEOPEN_WRITE, FILEDIALOG_NONE, GeGetByteOrder())) return FALSE;
for(LONG i=0; i < materialArray.GetCount(); i++)
{
BaseMaterial* mat = materialArray[i];
String str;
str = "newmtl " + mat->GetName() + "\n";
this->WriteString(str, fileMTL);
//Ka
str = "Ka 0.300000 0.300000 0.300000\n";
this->WriteString(str, fileMTL);
/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//Kd
if(getParameterLong(*mat, MATERIAL_USE_COLOR))
{
ExportChannel(document, fileMTL, *mat, MATERIAL_COLOR_SHADER, MATERIAL_COLOR_COLOR, "Kd");
}
//Ks
if(getParameterLong(*mat, MATERIAL_USE_REFLECTION))
{
ExportChannel(document, fileMTL, *mat, MATERIAL_REFLECTION_SHADER, MATERIAL_REFLECTION_COLOR, "Ks");
}
//Ns
str = "Ns 50.000000\n";
this->WriteString(str, fileMTL);
//Tr
str = "Tr 0.000000\n";
this->WriteString(str, fileMTL);
//illum
str = "illum 2\n";
this->WriteString(str, fileMTL);
this->WriteEndLine(fileMTL);
}
fileMTL->Close();
return TRUE;
}
示例13: pCalc
Bool CSVNodeData::UpdateCSVTable(GvNode* node, GvRun* run, GvCalc* calc) {
BaseDocument* doc = node->GetDocument();
if (m_initCsv) return TRUE;
// Obtain data to update the CSV Table. If *all* of those
// succeeded, the CSV table is updated.
GvPortCalc pCalc(node, &m_values, run, calc);
Bool header;
LONG delimiter;
Filename filename;
GvPort* pHeader = pCalc.GetInPort(CSVNODE_HEADER);
if (pHeader && pHeader->GetBool(&header, run)) ;
else return TRUE;
GvPort* pDelimiter = pCalc.GetInPort(CSVNODE_DELIMITER);
if (pDelimiter && pDelimiter->GetInteger(&delimiter, run)) ;
else return TRUE;
Bool ok = FALSE;
GvPort* pFilename = pCalc.GetInPort(CSVNODE_FILENAME);
filename = GvGetPortGeData(node, pFilename, run, &ok).GetFilename();
if (!ok) return TRUE;
// We now initialize the CSV Table and want to prevent any
// further initialization in the calculation cycle.
m_initCsv = TRUE;
// Validate and set the data to the CSV Table object.
if (m_pHeader != header) {
m_forceUpdate = TRUE;
}
m_pHeader = header;
m_table.SetHasHeader(header);
if (delimiter < 0 || delimiter > 255) {
delimiter = CSVNODE_DELIMITER_COMMA;
}
if (m_pDelimiter != delimiter) {
m_forceUpdate = TRUE;
}
m_pDelimiter = delimiter;
m_table.SetDelimiter((CHAR) delimiter);
// Make the CSV Filename relative to the node's document if the file
// does not exist.
if (doc && filename.Content() && !GeFExist(filename)) {
filename = doc->GetDocumentPath() + filename;
}
// Update the CSV Table.
Bool updated = FALSE;
Bool success = m_table.Init(filename, m_forceUpdate, &updated);
m_forceUpdate = FALSE;
return success;
}
示例14: pStep
bool DeriveProduct::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
StepResource pStep("Execute Wizard Item", "app", "58FE5CAB-E941-4E60-BA55-B29D70715FC4");
pStep->addProperty("Item", getName());
mpStep = pStep.get();
if (!extractInputArgs(pInArgList))
{
reportError("Unable to extract input arguments.", "5E158F48-6089-4A88-ABD0-55C717BD13E2");
return false;
}
View* pView = pInArgList->getPlugInArgValue<View>("View");
if (pView == NULL)
{
std::vector<Window*> windows;
Service<DesktopServices>()->getWindows(SPATIAL_DATA_WINDOW, windows);
if (!windows.empty())
{
pView = static_cast<SpatialDataWindow*>(windows.front())->getSpatialDataView();
}
}
if (pView == NULL)
{
reportError("No view provided.", "852F585B-D239-4C0A-B993-70EE68EC8DEE");
return false;
}
ProductWindow* pProductWindow = Service<DesktopServices>()->deriveProduct(pView);
if (pProductWindow == NULL)
{
reportError("Unable to derive product", "E24BB5A5-A675-4897-9C48-A4E4109379DF");
return false;
}
// Load a template if one is specified
Filename* pTemplate = pInArgList->getPlugInArgValue<Filename>("Template");
if (pTemplate != NULL)
{
if (!pProductWindow->getProductView()->loadTemplate(pTemplate->getFullPathAndName()))
{
reportError("Could not load the requested template!", "C99CE97E-3F0F-4CBB-8460-28D96D55596B");
return false;
}
}
// Set the output values
if (!pOutArgList->setPlugInArgValue("Window", pProductWindow) ||
!pOutArgList->setPlugInArgValue("View", pProductWindow->getProductView()))
{
reportError("Could not set the data set output value!", "3C53EDAE-DC70-4141-9759-ECD3EB9BE186");
return false;
}
reportComplete();
pStep->finalize(Message::Success);
return true;
}
示例15: TranslateLrocNacLabels
//Function to translate the labels
void TranslateLrocNacLabels ( Filename &labelFile, Cube *ocube ) {
//Pvl to store the labels
Pvl outLabel;
//Set up the directory where the translations are
PvlGroup dataDir(Preference::Preferences().FindGroup("DataDirectory"));
iString transDir = (string) dataDir["Lro"] + "/translations/";
Pvl labelPvl(labelFile.Expanded());
//Translate the Instrument group
Filename transFile(transDir + "lronacInstrument.trn");
PvlTranslationManager instrumentXlator(labelPvl, transFile.Expanded());
instrumentXlator.Auto(outLabel);
//Translate the Archive group
transFile = transDir + "lronacArchive.trn";
PvlTranslationManager archiveXlater(labelPvl, transFile.Expanded());
archiveXlater.Auto(outLabel);
// Set up the BandBin groups
PvlGroup bbin("BandBin");
bbin += PvlKeyword("FilterName", "BroadBand");
bbin += PvlKeyword("Center", 0.650, "micrometers");
bbin += PvlKeyword("Width", 0.150, "micrometers");
Pvl lab(labelFile.Expanded());
//Set up the Kernels group
PvlGroup kern("Kernels");
if (lab.FindKeyword("FRAME_ID")[0] == "LEFT")
kern += PvlKeyword("NaifFrameCode", -85600);
else
kern += PvlKeyword("NaifFrameCode", -85610);
PvlGroup inst = outLabel.FindGroup("Instrument", Pvl::Traverse);
if (lab.FindKeyword("FRAME_ID")[0] == "LEFT") {
inst.FindKeyword("InstrumentId") = "NACL";
inst.FindKeyword("InstrumentName") = "LUNAR RECONNAISSANCE ORBITER NARROW ANGLE CAMERA LEFT";
g_flip = false;
}
else {
inst.FindKeyword("InstrumentId") = "NACR";
inst.FindKeyword("InstrumentName") = "LUNAR RECONNAISSANCE ORBITER NARROW ANGLE CAMERA RIGHT";
}
inst += PvlKeyword("SpatialSumming", lab.FindKeyword("CROSSTRACK_SUMMING")[0] );
inst += PvlKeyword("SampleFirstPixel", 0 );
//Add all groups to the output cube
ocube->PutGroup(inst);
ocube->PutGroup(outLabel.FindGroup("Archive", Pvl::Traverse));
ocube->PutGroup(bbin);
ocube->PutGroup(kern);
}