MOCKSTACKS
EN
Questions And Answers

More Tutorials









Swift Mappers


Mappers provide a mechanism to specify the layout of mapped datasets on disk. This is needed when Swift must access files to transfer them to remote sites for execution or to pass to applications.

Swift provides a number of mappers that are useful in common cases. This section details those mappers. For more complex cases, it is possible to write application-specific mappers in Java and use them within a Swift script.

The Single File Mapper


The single_file_mapper maps a single physical file to a dataset.

Swift variable Filename
f myfile
f [0] INVALID
f.bar INVALID

parameter meaning
file The location of the physical file including path and file name.

Example:


file f <single_file_mapper;file="plot_outfile_param">;

There is a simplified syntax for this mapper:

file f <"plot_outfile_param">;

The Simple Mapper


The simple_mapper maps a file or a list of files into an array by prefix, suffix, and pattern. If more than one file is matched, each of the file names will be mapped as a subelement of the dataset.

Parameter Meaning
location A directory that the files are located.
prefix The prefix of the files
suffix The suffix of the files, for instance: ".txt"
padding The number of digits used to uniquely identify the mapped file. This is an optional parameter which defaults to 4.
pattern A UNIX glob style pattern, for instance: "*foo*" would match all file names that contain foo. When this mapper is used to specify output filenames, pattern is ignored.

type file;
file f <simple_mapper;prefix="foo", suffix=".txt">;

The above maps all filenames that start with foo and have an extension .txt into file f.

Swift variable Filename
f foo.txt

type messagefile;
(messagefile t) greeting(string m) {.
app {
echo m stdout=@filename(t);
}
}
messagefile outfile <simple_mapper;prefix="foo",suffix=".txt">;
outfile = greeting("hi");

This will output the string hi to the file foo.txt.

The simple_mapper can be used to map arrays. It will map the array index into the filename between the prefix and suffix.

type messagefile;
(messagefile t) greeting(string m) {
app {
echo m stdout=@filename(t);
}
}
messagefile outfile[] <simple_mapper;prefix="baz",suffix=".txt", padding=2>;
outfile[0] = greeting("hello");
outfile[1] = greeting("middle");
outfile[2] = greeting("goodbye");

Swift variable File name
outfile[0] baz00.txt
outfile[1] baz01.txt
outfile[2] baz02.txt

simple_mapper can be used to map structures. It will map the name of the structure member into the filename, between the prefix and the suffix.

type messagefile;
type mystruct {
messagefile left;
messagefile right;
};
(messagefile t) greeting(string m) {
app {
echo m stdout=@filename(t);
}
}
mystruct out <simple_mapper;prefix="qux",suffix=".txt">;
out.left = greeting("hello");
out.right = greeting("goodbye");

This will output the string "hello" into the file qux.left.txt and the string "goodbye" into the file qux.right.txt.


Conclusion

In this page (written and validated by ) you learned about Swift Mappers . What's Next? If you are interested in completing Swift tutorial, your next topic will be learning about: Swift Concurrent Mapper.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.