Skip to main content

Common Fluids Format 2024 R2

ansys::Project::Iterator Class Reference

Last update: 16.07.2025

Pointer to a project location. More...

#include "Iterator.hpp"

Public Member Functions

 Iterator ()
 Null iterator contructor (ok() is false)
 
 Iterator (const Error &pError)
 Error iterator constructor (ok() is false, error message provided) More...
 
bool ok () const
 True if the iterator points to a valid location in the project.
 
void setError (const Error &pError)
 Set an error state in the Iterator. Will make it invalid (!ok())
 
const ErrorgetError () const
 Return the error state of an invalid iterator. An null iteration might not have an error state.
 
bool operator== (const Iterator &pObj) const
 True if the two iterators point to the same target. More...
 
PItemType getType () const
 Return the project item type as a PItemType enum.
 
std::string getTypeAsString () const
 Return the project item type as a string.
 
std::string getSubclass () const
 Return name of the subclass (if any) for the item. More...
 
std::string getName () const
 Name of the project item (might differ from URL filename)
 
Error rename (const std::string &pName)
 Rename the project item.
 
Path getPath () const
 Return the item full Path in the project. More...
 
Iterator getParent () const
 Return the iterator to the parent folder. More...
 
Iterator getParentOfType (const std::string &pType) const
 Go up in the chain of parent and search for matching getTypeAsString()
 
Iterator getParentOfSubclass (const std::string &pSubclass) const
 Go up in the chain of parent and search for matching getSubclass()
 
int getProjectId () const
 Return the unique project ID for this iterator. More...
 
bool isReadOnly () const
 Indicates if the target project or location is read-only. More...
 
MetadatagetMeta ()
 Returns the Metadata for this project item. More...
 
const MetadatagetMeta () const
 Returns a constant reference to the Metadata for this project item. More...
 
MetadatagetRuntimeMeta ()
 Returns a reference to the runtime Metadata. More...
 
const MetadatagetRuntimeMeta () const
 Constant version of getRuntimeMeta()
 
std::vector< Iteratorfind (const Query &pQuery, bool pFollowSymlink=false) const
 Execute a Query onto the current Iterator. More...
 
bool isFile () const
 True if the -valid- pointed object is a File. More...
 
bool isLink () const
 True if the -valid- pointed object is a Link. More...
 
bool isFolder () const
 True if the -valid- pointed object is a Folder. More...
 
Iterator newFolder (const std::string &pName)
 Creates a new project-only folder at this location in the project. More...
 
Iterator newFolder (const std::string &pName, const URL &pURL)
 Creates a new folder associated with disk storage. More...
 
Iterator newFile (const std::string &pName)
 Creates a new project-only file at this location in the project. More...
 
Iterator newFile (const std::string &pName, const URL &pURL, bool pImport=false)
 Creates a new file associated with disk storage. More...
 
Iterator newLink (const std::string &pName, const Iterator &pTarget)
 Create a project-level symbolic link.
 
Iterator getChild (const std::string &pName) const
 Folder - return child item by specified name.
 
Iterator get (const Path &pName) const
 Folder - return child sub-item at specified Path.
 
Iterator getByURL (const URL &pRelativeURL) const
 Folder - check if a child points to the specified URL. More...
 
std::vector< std::string > getChildNames () const
 Folder - return list of children names.
 
std::vector< IteratorgetChildList () const
 Folder - return list of children Iterator.
 
std::vector< IteratorgetChildListOfSubclass (std::string pSubclass) const
 Folder - return list of children Iterator of matching subclass. More...
 
std::vector< std::string > getFolderOtherURLSubItems (bool pFolders) const
 Folder - return list of files in the folder URL, unknown by the project. More...
 
Error removeItem (const std::string &pName, bool pFlagRecursive=false)
 Folder - remove an item from the folder. Not erased from storage. More...
 
Error moveTo (Iterator pTargetFolder)
 Iterator - move from current folder to a target folder. More...
 
void setURL (const URL &pURL)
 File/Folder - set the URL pointed by this item. More...
 
URL getURL () const
 File/Folder - returns the URL pointed by this item. More...
 
URL getURLFromRoot () const
 File/Folder - returns the relative URL as computed from the root of the project.
 
URL getFullURL () const
 File/Folder - returns the absolute, including the project location - if suitable.
 
bool urlExists () const
 File/Folder - indicates if the item URL points to a valid/accessible file/folder.
 
bool isURLEditable () const
 Indicates if the URL is ok to be modified by the user. More...
 
void clearChecksum ()
 Clear the stored checksum value for the pointed file.
 
Error computeChecksum (std::string &pChecksum, bool pFlagStore)
 Compute a checksum for the stored file.
 
Error getStoredChecksum (std::string &pChecksum) const
 Get the stored checksum for the file, can be used to compare with the current computeChecksum()
 
Iterator getTarget () const
 Link - Return the Iterator of the link target.
 
void setTarget (const Iterator &pIter)
 Link - Change the Iterator of the link target.
 
bool isSubProject () const
 Link - Indicates if this is a link to a subproject. More...
 

Detailed Description

Pointer to a project location.

An Iterator is a pointer to a project location, the location might be null, invalid or to a good object. The Iterator contains a Error message, functions returning an Iterator as return value might fill the Iterator with the error message indicating the failure.

 Iterator it;
 it.ok() == false;  // null iterator

it = prj.get("bad path.cas"); it.ok() == false; // false if not found it.getError().getErrorsString(); // string: "Project path should start with /"

it = prj.get("/Simulation/file.cas"); it.ok() == true; // true if found

prj.closeProject() it.ok() == false; // project has been closed, iterator is now invalid

The Iterator can be used to execute actions on the pointed object. The Iterator has a base type ( getType() = PIFile, PIFolder, PILink ) and only suitable actions to the target type can be executed, type mismatch or the use of an empty iterator will return an error , error iterator or some default/empty state

 Iterator it;
vector<string> childs = it.getChildList(); // empty, no error message

Constructor & Destructor Documentation

◆ Iterator()

ansys::Project::Iterator::Iterator ( const Error pError)

Error iterator constructor (ok() is false, error message provided)

Parameters
pErrorError message, will be returned by getError()

Member Function Documentation

◆ find()

std::vector< Iterator > ansys::Project::Iterator::find ( const Query pQuery,
bool  pFollowSymlink = false 
) const

Execute a Query onto the current Iterator.

  • pQuery Search query to be executed
  • pFollowSymlink true if the query should go through links or ignore them
Returns
The list of Iterator matching the query, empty vector if none.

◆ getByURL()

Iterator ansys::Project::Iterator::getByURL ( const URL pRelativeURL) const

Folder - check if a child points to the specified URL.

Parameters
pRelativeURLRelative URL from the folder location

◆ getChildListOfSubclass()

std::vector< Iterator > ansys::Project::Iterator::getChildListOfSubclass ( std::string  pSubclass) const

Folder - return list of children Iterator of matching subclass.

Will also traverse subproject links automatically

◆ getFolderOtherURLSubItems()

std::vector< std::string > ansys::Project::Iterator::getFolderOtherURLSubItems ( bool  pFolders) const

Folder - return list of files in the folder URL, unknown by the project.

Only works if the folder URL is accessible.

◆ getMeta() [1/2]

Metadata & ansys::Project::Iterator::getMeta ( )

Returns the Metadata for this project item.

The Metadata object can be modified and the changes will be stored in the project. If the iterator is not valid, any changes to the Metadata are ignored and lost.

◆ getMeta() [2/2]

const Metadata & ansys::Project::Iterator::getMeta ( ) const

Returns a constant reference to the Metadata for this project item.

The Metadata object cannot be modified If the iterator is not valid, the returned Metadata is empty

◆ getParent()

Iterator ansys::Project::Iterator::getParent ( ) const

Return the iterator to the parent folder.

Returns null iterator in error, or the current iterator is the parent folder of the project already.

◆ getPath()

Path ansys::Project::Iterator::getPath ( ) const

Return the item full Path in the project.

The Path in the project is a global path starting by / and identifying components by their project Name (the project Path might differ from the filesystem URL, or might refer to folders/files which only exist in the project index, and not on disk)

◆ getProjectId()

int ansys::Project::Iterator::getProjectId ( ) const

Return the unique project ID for this iterator.

Permits to check if an iterator is from a specific project. The project ID might differ across different executions.

◆ getRuntimeMeta()

Metadata & ansys::Project::Iterator::getRuntimeMeta ( )

Returns a reference to the runtime Metadata.

The runtime Metadata is a second Metadata storage, which contains values which are not saved in the project.

◆ getSubclass()

std::string ansys::Project::Iterator::getSubclass ( ) const

Return name of the subclass (if any) for the item.

See Simulation , Run , Output , Result , etc.

◆ getURL()

URL ansys::Project::Iterator::getURL ( ) const

File/Folder - returns the URL pointed by this item.

See setURL(const URL&)

◆ isFile()

bool ansys::Project::Iterator::isFile ( ) const

True if the -valid- pointed object is a File.

Checks if the iterator points to an item of the File type in the project index. It might be a project only file or an actual file on disk. See getURL() and urlExists()

◆ isFolder()

bool ansys::Project::Iterator::isFolder ( ) const

True if the -valid- pointed object is a Folder.

Checks if the iterator points to an item of the Folder type in the project index. It might be a project only file or an actual file on disk. See getURL() and urlExists()

◆ isLink()

bool ansys::Project::Iterator::isLink ( ) const

True if the -valid- pointed object is a Link.

Checks if the iterator points to an item of the Link type This is a project-level Link concept created by newLink()

◆ isReadOnly()

bool ansys::Project::Iterator::isReadOnly ( ) const

Indicates if the target project or location is read-only.

All iterators of a read-only project are read-only, many iterator actions will have no effect or fail on a read-only project.

◆ isSubProject()

bool ansys::Project::Iterator::isSubProject ( ) const

Link - Indicates if this is a link to a subproject.

If the link target is not ok() means the subproject is not loaded.

◆ isURLEditable()

bool ansys::Project::Iterator::isURLEditable ( ) const

Indicates if the URL is ok to be modified by the user.

Two items affect this suggested state:

  • URL are not editable by default is a managed project, are editable by default in a free-storage project
  • The runtime metadata 'url-editable' can be set on the iterator, or any parent folder, to 0 or 1

◆ moveTo()

Error ansys::Project::Iterator::moveTo ( Iterator  pTarget)

Iterator - move from current folder to a target folder.

This is a project only operation, URL and disk data need to be udpated separately (Storage::moveFile())

Parameters
pTargetTarget folder to move to

◆ newFile() [1/2]

Iterator ansys::Project::Iterator::newFile ( const std::string &  pName)

Creates a new project-only file at this location in the project.

A project-only file is not created in the disk storage, its only stored in the project index. Will fail if : name already in use, target iterator is not a folder, read-only project, etc.

  • pName Name of the new project file in project Path

◆ newFile() [2/2]

Iterator ansys::Project::Iterator::newFile ( const std::string &  pName,
const URL pURL,
bool  pImport = false 
)

Creates a new file associated with disk storage.

If pURL is empty, the existing URL name is assumed the same as the pName argument If pImport is enabled, the source URL is copied in the project folder

 it.newFile("main-case","file.cas");  // Refers to an existing or future file here
 it.newFile("demo.cas","/mnt/meshes/database.cas"); // file points to some location
 it.newFile("demo2.cas","/mnt/meshes/database.cas",true); // file is copied in folder
  • pName Name of the new project file in project Path
  • pURL URL of the file location
  • pImport true if this is an import operation

◆ newFolder() [1/2]

Iterator ansys::Project::Iterator::newFolder ( const std::string &  pName)

Creates a new project-only folder at this location in the project.

A project-only folder is not created in the disk storage, its only stored in the project index. Will fail if : name already in use, target iterator is not a folder, read-only project, etc.

  • pName Name of the new project folder in project Path

◆ newFolder() [2/2]

Iterator ansys::Project::Iterator::newFolder ( const std::string &  pName,
const URL pURL 
)

Creates a new folder associated with disk storage.

If URL is empty, and the project is managed, a new folder is created in the filesystem storage of the project.

 it.newFolder("CADs","");  // A new folder is created on disk, in the project
 it.newFolder("Meshes","/mnt/meshes/"); // folder points to some location

If the project is free-storage, an empty URL will create a project-only folder similar to newFolder(const std::string&);

  • pName Name of the new project folder in project Path
  • pURL URL of the folder location

◆ operator==()

bool ansys::Project::Iterator::operator== ( const Iterator pObj) const

True if the two iterators point to the same target.

Invalid/error iterator will always be unequal to another iterator

◆ removeItem()

Error ansys::Project::Iterator::removeItem ( const std::string &  pName,
bool  pFlagRecursive = false 
)

Folder - remove an item from the folder. Not erased from storage.

Parameters
pFlagRecursive- true will erase a subfolder and its content

◆ setURL()

void ansys::Project::Iterator::setURL ( const URL pURL)

File/Folder - set the URL pointed by this item.

The URL can either be relative ( "./filename" ), and is then assumed to be in the enclosing folder URL. The URL can also be absolute, and is not tied to the location of the enclosing folder.

Connect with Ansys