src/AttributeFinder.h
branchv_0
changeset 9 b4f29fb16159
parent 8 eb1ecb37c6b7
child 24 4353cd19a6b5
equal deleted inserted replaced
8:eb1ecb37c6b7 9:b4f29fb16159
    35 
    35 
    36 class AttributeFinder {
    36 class AttributeFinder {
    37 protected:
    37 protected:
    38 	fs::path currentFile;
    38 	fs::path currentFile;
    39 	string currentFileRaw;
    39 	string currentFileRaw;
    40 public:
    40 	bool currentFileExists;
    41 
       
    42 	/**
       
    43 	 * Single requested fields might generate multiple attributes in the relation.
       
    44 	 * But usually it is 1:1.
       
    45 	 * @param field requested field from the user (usually from CLI arguments)
       
    46 	 * @return attribute metadata to be used in the RelationalWriter.startRelation()
       
    47 	 */
       
    48 	virtual vector<AttributeMetadata> toMetadata(const RequestedField& field) = 0;
       
    49 
       
    50 	/**
       
    51 	 * Writing of the record for current file is starting.
       
    52 	 * Following writeField() calls are related to this file.
       
    53 	 * @param file path to the file
       
    54 	 * @param fileRaw raw file name as it was on the input
       
    55 	 */
       
    56 	virtual void startFile(const fs::path& file, const string& fileRaw) {
       
    57 		currentFile = file;
       
    58 		currentFileRaw = fileRaw;
       
    59 	}
       
    60 
       
    61 	/**
       
    62 	 * Writing of the record for current file is finished. All resources linked to this file should be released.
       
    63 	 */
       
    64 	virtual void endFile() {
       
    65 		currentFile.clear();
       
    66 		currentFileRaw.clear();
       
    67 	}
       
    68 
    41 
    69 	/**
    42 	/**
    70 	 * Writes field attribute(s). The attribute count must match with count of AttributeMetadata returned in toMetadata().
    43 	 * Writes field attribute(s). The attribute count must match with count of AttributeMetadata returned in toMetadata().
    71 	 * @param writer
    44 	 * @param writer
    72 	 * @param field
    45 	 * @param field
    73 	 */
    46 	 */
    74 	virtual void writeField(RelationalWriter* writer, const RequestedField& field) = 0;
    47 	virtual void writeFieldOfExistingFile(RelationalWriter* writer, const RequestedField& field) = 0;
    75 
    48 
    76 	/**
    49 	/**
    77 	 * Writes empty attribute(s) in case of non-existent file or an error. 
    50 	 * Writes empty attribute(s) in case of non-existent file or an error. 
    78 	 * The attribute count must match with count of AttributeMetadata returned in toMetadata().
    51 	 * The attribute count must match with count of AttributeMetadata returned in toMetadata().
    79 	 * @param writer
    52 	 * @param writer
    96 					throw RelpipeWriterException(L"Unsupported attribute type in writeEmptyField().");
    69 					throw RelpipeWriterException(L"Unsupported attribute type in writeEmptyField().");
    97 			}
    70 			}
    98 		}
    71 		}
    99 	}
    72 	}
   100 
    73 
       
    74 public:
       
    75 
       
    76 	/**
       
    77 	 * Single requested fields might generate multiple attributes in the relation.
       
    78 	 * But usually it is 1:1.
       
    79 	 * @param field requested field from the user (usually from CLI arguments)
       
    80 	 * @return attribute metadata to be used in the RelationalWriter.startRelation()
       
    81 	 */
       
    82 	virtual vector<AttributeMetadata> toMetadata(const RequestedField& field) = 0;
       
    83 
       
    84 	/**
       
    85 	 * Writing of the record for current file is starting.
       
    86 	 * Following writeField() calls are related to this file.
       
    87 	 * @param file path to the file
       
    88 	 * @param fileRaw raw file name as it was on the input
       
    89 	 */
       
    90 	virtual void startFile(const fs::path& file, const string& fileRaw, bool exists) {
       
    91 		currentFile = file;
       
    92 		currentFileRaw = fileRaw;
       
    93 		currentFileExists = exists;
       
    94 	}
       
    95 
       
    96 	virtual void writeField(RelationalWriter* writer, const RequestedField& field) {
       
    97 		if (currentFileExists) writeFieldOfExistingFile(writer, field);
       
    98 		else writeEmptyField(writer, field);
       
    99 	}
       
   100 
       
   101 	/**
       
   102 	 * Writing of the record for current file is finished. All resources linked to this file should be released.
       
   103 	 */
       
   104 	virtual void endFile() {
       
   105 		currentFile.clear();
       
   106 		currentFileRaw.clear();
       
   107 	}
       
   108 
   101 	virtual ~AttributeFinder() {
   109 	virtual ~AttributeFinder() {
   102 	}
   110 	}
   103 };
   111 };
   104 
   112 
   105 }
   113 }