Skip to content

Commit fab2faa

Browse files
add comments to the class
1 parent 251af2f commit fab2faa

File tree

1 file changed

+144
-1
lines changed

1 file changed

+144
-1
lines changed

code/logic/fossil/io/stream.h

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ namespace fossil {
344344
*/
345345
class Stream {
346346
public:
347-
// Existing functions...
348347

349348
/**
350349
* Reopen a stream with a new file.
@@ -361,6 +360,17 @@ namespace fossil {
361360
return fossil_fstream_freopen(stream, filename, mode, file);
362361
}
363362

363+
/**
364+
* Reopen a stream with a new file.
365+
*
366+
* This function reopens a stream with a new file.
367+
*
368+
* @param stream Pointer to the fossil_fstream_t structure to reopen.
369+
* @param filename The name of the file to reopen.
370+
* @param mode The mode in which to reopen the file.
371+
* @param file Pointer to the FILE structure to reopen.
372+
* @return 0 on success, non-zero on failure.
373+
*/
364374
static int32_t freopen(fossil_fstream_t *stream, const std::string &filename, const std::string &mode, FILE *file) {
365375
return fossil_fstream_freopen(stream, filename.c_str(), mode.c_str(), file);
366376
}
@@ -379,6 +389,16 @@ namespace fossil {
379389
return fossil_fstream_open(stream, filename, mode);
380390
}
381391

392+
/**
393+
* Open a stream for file operations.
394+
*
395+
* This function opens a file stream, allowing read or write operations on the specified file.
396+
*
397+
* @param stream Pointer to the fossil_fstream_t structure to store the opened stream.
398+
* @param filename The name of the file to be opened.
399+
* @param mode The mode in which to open the file (e.g., "r" for read, "w" for write).
400+
* @return 0 on success, non-zero on failure.
401+
*/
382402
static int32_t open(fossil_fstream_t *stream, const std::string &filename, const std::string &mode) {
383403
return fossil_fstream_open(stream, filename.c_str(), mode.c_str());
384404
}
@@ -490,6 +510,15 @@ namespace fossil {
490510
return fossil_fstream_save(stream, new_filename);
491511
}
492512

513+
/**
514+
* Save an open stream to a new file.
515+
*
516+
* This function saves the contents of an open stream to a new file.
517+
*
518+
* @param stream Pointer to the fossil_fstream_t structure to be saved.
519+
* @param new_filename The name of the new file to save to.
520+
* @return 0 on success, non-zero on failure.
521+
*/
493522
static int32_t save(fossil_fstream_t *stream, const std::string &new_filename) {
494523
return fossil_fstream_save(stream, new_filename.c_str());
495524
}
@@ -507,6 +536,15 @@ namespace fossil {
507536
return fossil_fstream_copy(source_filename, destination_filename);
508537
}
509538

539+
/**
540+
* Copy a file from the source to the destination.
541+
*
542+
* This function copies a file from a source file to a destination file.
543+
*
544+
* @param source_filename The name of the source file.
545+
* @param destination_filename The name of the destination file.
546+
* @return 0 on success, non-zero on failure.
547+
*/
510548
static int32_t copy(const std::string &source_filename, const std::string &destination_filename) {
511549
return fossil_fstream_copy(source_filename.c_str(), destination_filename.c_str());
512550
}
@@ -523,6 +561,14 @@ namespace fossil {
523561
return fossil_fstream_remove(filename);
524562
}
525563

564+
/**
565+
* Remove a file stream.
566+
*
567+
* This function removes a file stream.
568+
*
569+
* @param filename The name of the file to remove.
570+
* @return 0 on success, non-zero on failure.
571+
*/
526572
static int32_t remove(const std::string &filename) {
527573
return fossil_fstream_remove(filename.c_str());
528574
}
@@ -540,6 +586,15 @@ namespace fossil {
540586
return fossil_fstream_rename(old_filename, new_filename);
541587
}
542588

589+
/**
590+
* Rename a file or directory.
591+
*
592+
* This function renames a file or directory.
593+
*
594+
* @param old_filename The current name of the file or directory.
595+
* @param new_filename The new name to assign to the file or directory.
596+
* @return 0 on success, non-zero on failure.
597+
*/
543598
static int32_t rename(const std::string &old_filename, const std::string &new_filename) {
544599
return fossil_fstream_rename(old_filename.c_str(), new_filename.c_str());
545600
}
@@ -594,6 +649,15 @@ namespace fossil {
594649
return fossil_fstream_rotate(filename, n);
595650
}
596651

652+
/**
653+
* Rotate a file stream.
654+
*
655+
* This function rotates a file stream.
656+
*
657+
* @param filename The name of the file to rotate.
658+
* @param n The number of rotations to perform.
659+
* @return 0 on success, non-zero on failure.
660+
*/
597661
static int32_t rotate(const std::string &filename, int32_t n) {
598662
return fossil_fstream_rotate(filename.c_str(), n);
599663
}
@@ -611,6 +675,15 @@ namespace fossil {
611675
return fossil_fstream_backup(filename, backup_suffix);
612676
}
613677

678+
/**
679+
* Create a backup of a file with a specified backup suffix.
680+
*
681+
* This function creates a backup of a file with the given suffix.
682+
*
683+
* @param filename The name of the file to create a backup for.
684+
* @param backup_suffix The suffix to be appended to the backup file.
685+
* @return 0 on success, non-zero on failure.
686+
*/
614687
static int32_t backup(const std::string &filename, const std::string &backup_suffix) {
615688
return fossil_fstream_backup(filename.c_str(), backup_suffix.c_str());
616689
}
@@ -627,6 +700,14 @@ namespace fossil {
627700
return fossil_fstream_file_exists(filename);
628701
}
629702

703+
/**
704+
* Check if a file exists.
705+
*
706+
* This function checks if a file exists.
707+
*
708+
* @param filename The name of the file to check for existence.
709+
* @return 1 if the file exists, 0 if not.
710+
*/
630711
static int32_t file_exists(const std::string &filename) {
631712
return fossil_fstream_file_exists(filename.c_str());
632713
}
@@ -655,6 +736,14 @@ namespace fossil {
655736
return fossil_fstream_delete(filename);
656737
}
657738

739+
/**
740+
* Delete a file.
741+
*
742+
* This function deletes a file.
743+
*
744+
* @param filename The name of the file to be deleted.
745+
* @return 0 on success, non-zero on failure.
746+
*/
658747
static int32_t delete_file(const std::string &filename) {
659748
return fossil_fstream_delete(filename.c_str());
660749
}
@@ -671,6 +760,14 @@ namespace fossil {
671760
return fossil_fstream_get_type(filename);
672761
}
673762

763+
/**
764+
* Get the type of a file stream.
765+
*
766+
* This function retrieves the type of a file stream.
767+
*
768+
* @param filename The name of the file to get the type of.
769+
* @return The type of the file stream.
770+
*/
674771
static int get_type(const std::string &filename) {
675772
return fossil_fstream_get_type(filename.c_str());
676773
}
@@ -687,6 +784,14 @@ namespace fossil {
687784
return fossil_fstream_is_readable(filename);
688785
}
689786

787+
/**
788+
* Check if a file is readable.
789+
*
790+
* This function checks if a file has read permissions.
791+
*
792+
* @param filename The name of the file to check.
793+
* @return 1 if readable, 0 otherwise.
794+
*/
690795
static int32_t is_readable(const std::string &filename) {
691796
return fossil_fstream_is_readable(filename.c_str());
692797
}
@@ -703,6 +808,14 @@ namespace fossil {
703808
return fossil_fstream_is_writable(filename);
704809
}
705810

811+
/**
812+
* Check if a file is writable.
813+
*
814+
* This function checks if a file has write permissions.
815+
*
816+
* @param filename The name of the file to check.
817+
* @return 1 if writable, 0 otherwise.
818+
*/
706819
static int32_t is_writable(const std::string &filename) {
707820
return fossil_fstream_is_writable(filename.c_str());
708821
}
@@ -719,6 +832,14 @@ namespace fossil {
719832
return fossil_fstream_is_executable(filename);
720833
}
721834

835+
/**
836+
* Check if a file is executable.
837+
*
838+
* This function checks if a file has execute permissions.
839+
*
840+
* @param filename The name of the file to check.
841+
* @return 1 if executable, 0 otherwise.
842+
*/
722843
static int32_t is_executable(const std::string &filename) {
723844
return fossil_fstream_is_executable(filename.c_str());
724845
}
@@ -736,6 +857,15 @@ namespace fossil {
736857
return fossil_fstream_set_permissions(filename, mode);
737858
}
738859

860+
/**
861+
* Set file permissions.
862+
*
863+
* This function sets the permissions for a file.
864+
*
865+
* @param filename The name of the file to set permissions for.
866+
* @param mode The permissions to set (POSIX: chmod-style).
867+
* @return 0 on success, non-zero on failure.
868+
*/
739869
static int32_t set_permissions(const std::string &filename, int32_t mode) {
740870
return fossil_fstream_set_permissions(filename.c_str(), mode);
741871
}
@@ -753,10 +883,23 @@ namespace fossil {
753883
return fossil_fstream_get_permissions(filename, mode);
754884
}
755885

886+
/**
887+
* Get file permissions.
888+
*
889+
* This function retrieves the permissions of a file.
890+
*
891+
* @param filename The name of the file to retrieve permissions for.
892+
* @param mode Pointer to store the retrieved permissions (POSIX style).
893+
* @return 0 on success, non-zero on failure.
894+
*/
756895
static int32_t get_permissions(const std::string &filename, int32_t *mode) {
757896
return fossil_fstream_get_permissions(filename.c_str(), mode);
758897
}
759898

899+
};
900+
901+
} // namespace io
902+
760903
} // namespace fossil
761904

762905
#endif

0 commit comments

Comments
 (0)