ansys::Project::Iterator Class Reference
Last update: 16.07.2025Pointer 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 Error & | getError () 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... | |
| Metadata & | getMeta () |
| Returns the Metadata for this project item. More... | |
| const Metadata & | getMeta () const |
| Returns a constant reference to the Metadata for this project item. More... | |
| Metadata & | getRuntimeMeta () |
| Returns a reference to the runtime Metadata. More... | |
| const Metadata & | getRuntimeMeta () const |
| Constant version of getRuntimeMeta() | |
| std::vector< Iterator > | find (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< Iterator > | getChildList () const |
| Folder - return list of children Iterator. | |
| std::vector< Iterator > | getChildListOfSubclass (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 iteratorit = 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
-
pError Error message, will be returned by getError()
Member Function Documentation
◆ find()
◆ getByURL()
◆ 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 |
◆ getMeta() [1/2]
| Metadata & ansys::Project::Iterator::getMeta | ( | ) |
◆ getMeta() [2/2]
| const Metadata & ansys::Project::Iterator::getMeta | ( | ) | const |
◆ 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 |
◆ 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 | ( | ) |
◆ 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()
◆ 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 |
◆ moveTo()
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
-
pTarget Target 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
◆ 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]
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&);
◆ 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